From 94dc963b558b3d37906af53eca45c5ae807a9e84 Mon Sep 17 00:00:00 2001 From: Dmitriy Vyukov Date: Sat, 15 Jun 2013 16:07:06 +0400 Subject: [PATCH] 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 --- src/pkg/runtime/mgc0.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pkg/runtime/mgc0.c b/src/pkg/runtime/mgc0.c index a55ee49c777..4be0eeb0dbd 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)