From: Keith Randall Date: Thu, 24 Jul 2014 21:37:34 +0000 (-0700) Subject: runtime: set sweepgen atomically before updating span state X-Git-Tag: go1.4beta1~1019 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=3590d9ce695baa7535537e3d1404de52bf94fae5;p=gostls13.git runtime: set sweepgen atomically before updating span state Sweepone may be running while a new span is allocating. It must not see the state updated while the sweepgen is unset. Fixes #8399 LGTM=dvyukov R=golang-codereviews, dvyukov CC=golang-codereviews https://golang.org/cl/118050043 --- diff --git a/src/pkg/runtime/mheap.c b/src/pkg/runtime/mheap.c index 7ae5a399b3..3a5981d3c7 100644 --- a/src/pkg/runtime/mheap.c +++ b/src/pkg/runtime/mheap.c @@ -189,13 +189,13 @@ mheap_alloc(MHeap *h, uintptr npage, int32 sizeclass, bool large) if(s != nil) { // Record span info, because gc needs to be // able to map interior pointer to containing span. + runtime·atomicstore(&s->sweepgen, h->sweepgen); s->state = MSpanInUse; s->freelist = nil; s->ref = 0; s->sizeclass = sizeclass; s->elemsize = (sizeclass==0 ? s->npages<types.compression = MTypes_Empty; - s->sweepgen = h->sweepgen; // update stats, sweep lists if(large) {