From: Russ Cox Date: Thu, 8 Apr 2010 03:38:02 +0000 (-0700) Subject: runtime: use explicit flag when finalizer goroutine is waiting X-Git-Tag: weekly.2010-04-13~44 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=24c58174b27e1cd2cbaa34e392c6a9e7957a6afa;p=gostls13.git runtime: use explicit flag when finalizer goroutine is waiting Avoids spurious wakeups during other sleeping by that goroutine. Fixes #711. R=r CC=golang-dev https://golang.org/cl/902041 --- diff --git a/src/pkg/runtime/mgc0.c b/src/pkg/runtime/mgc0.c index 8cde102094..f61c10c603 100644 --- a/src/pkg/runtime/mgc0.c +++ b/src/pkg/runtime/mgc0.c @@ -25,6 +25,8 @@ extern byte end[]; static G *fing; static Finalizer *finq; +static int32 fingwait; + static void sweepblock(byte*, int64, uint32*, int32); static void runfinq(void); @@ -306,8 +308,10 @@ gc(int32 force) // kick off or wake up goroutine to run queued finalizers if(fing == nil) fing = newproc1((byte*)runfinq, nil, 0, 0); - else if(fing->status == Gwaiting) + else if(fingwait) { ready(fing); + fingwait = 0; + } } m->locks--; @@ -340,6 +344,7 @@ runfinq(void) f = finq; finq = nil; if(f == nil) { + fingwait = 1; g->status = Gwaiting; gosched(); continue;