From: Dmitriy Vyukov Date: Sat, 15 Jun 2013 12:07:06 +0000 (+0400) Subject: runtime: fix race condition between GC and setGCPercent X-Git-Tag: go1.2rc2~1239 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=94dc963b558b3d37906af53eca45c5ae807a9e84;p=gostls13.git runtime: fix race condition between GC and setGCPercent 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 --- diff --git a/src/pkg/runtime/mgc0.c b/src/pkg/runtime/mgc0.c index a55ee49c77..4be0eeb0db 100644 --- a/src/pkg/runtime/mgc0.c +++ b/src/pkg/runtime/mgc0.c @@ -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)