]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: document concurrency of mheap.spans
authorAustin Clements <austin@google.com>
Wed, 9 Aug 2017 15:19:24 +0000 (11:19 -0400)
committerAustin Clements <austin@google.com>
Wed, 9 Aug 2017 16:06:23 +0000 (16:06 +0000)
We use lock-free reads from mheap.spans, but the safety of these is
somewhat subtle. Document this.

Change-Id: I928c893232176135308e38bed788d5f84ff11533
Reviewed-on: https://go-review.googlesource.com/54310
Reviewed-by: Rick Hudson <rlh@golang.org>
src/runtime/mheap.go

index 893587e5d2243a0a99f8a131853a500c7d9a5d3f..bf4112576469afa03de9a5e45147b23b48e96ef6 100644 (file)
@@ -56,6 +56,12 @@ type mheap struct {
        // Internal pages map to an arbitrary span.
        // For pages that have never been allocated, spans entries are nil.
        //
+       // Modifications are protected by mheap.lock. Reads can be
+       // performed without locking, but ONLY from indexes that are
+       // known to contain in-use or stack spans. This means there
+       // must not be a safe-point between establishing that an
+       // address is live and looking it up in the spans array.
+       //
        // This is backed by a reserved region of the address space so
        // it can grow without moving. The memory up to len(spans) is
        // mapped. cap(spans) indicates the total reserved memory.