diff options
author | Hector Chu <hectorchu@gmail.com> | 2011-07-29 17:39:02 -0400 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2011-07-29 17:39:02 -0400 |
commit | 9bc58accce0ab83dab6ca08f0cc319e75f7dd889 (patch) | |
tree | 391d92c8be5f27c543886beedad834f7fdb3ad24 | |
parent | 31442a6737c98ba5297b348b87bc47edecf667c1 (diff) | |
download | go-9bc58accce0ab83dab6ca08f0cc319e75f7dd889.tar.gz go-9bc58accce0ab83dab6ca08f0cc319e75f7dd889.zip |
runtime: fix scheduling race
Affects programs using cgo or runtime.LockOSThread.
Fixes #2100.
R=rsc, dvyukov
CC=golang-dev
https://golang.org/cl/4810059
-rw-r--r-- | src/pkg/runtime/proc.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/pkg/runtime/proc.c b/src/pkg/runtime/proc.c index ffaf44ddd8..6d8f6990b2 100644 --- a/src/pkg/runtime/proc.c +++ b/src/pkg/runtime/proc.c @@ -486,8 +486,16 @@ nextgandunlock(void) // We can only run one g, and it's not available. // Make sure some other cpu is running to handle // the ordinary run queue. - if(runtime·sched.gwait != 0) + if(runtime·sched.gwait != 0) { matchmg(); + // m->lockedg might have been on the queue. + if(m->nextg != nil) { + gp = m->nextg; + m->nextg = nil; + schedunlock(); + return gp; + } + } } else { // Look for work on global queue. while(haveg() && canaddmcpu()) { |