]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: fix race condition between GC and setGCPercent
authorDmitriy Vyukov <dvyukov@google.com>
Sat, 15 Jun 2013 12:07:06 +0000 (16:07 +0400)
committerDmitriy Vyukov <dvyukov@google.com>
Sat, 15 Jun 2013 12:07:06 +0000 (16:07 +0400)
If first GC runs concurrently with setGCPercent,
it can overwrite gcpercent value with default.

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/10242047

src/pkg/runtime/mgc0.c

index a55ee49c7777cdc82b9abefa740181b9258e5968..4be0eeb0dbdc1852b7d923715a0eca82405ad25e 100644 (file)
@@ -1974,7 +1974,10 @@ runtime·gc(int32 force)
                return;
 
        if(gcpercent == GcpercentUnknown) {     // first time through
-               gcpercent = readgogc();
+               runtime·lock(&runtime·mheap);
+               if(gcpercent == GcpercentUnknown)
+                       gcpercent = readgogc();
+               runtime·unlock(&runtime·mheap);
 
                p = runtime·getenv("GOGCTRACE");
                if(p != nil)