]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: fix scheduling race
authorHector Chu <hectorchu@gmail.com>
Fri, 29 Jul 2011 21:39:02 +0000 (17:39 -0400)
committerRuss Cox <rsc@golang.org>
Fri, 29 Jul 2011 21:39:02 +0000 (17:39 -0400)
Affects programs using cgo or runtime.LockOSThread.

Fixes #2100.

R=rsc, dvyukov
CC=golang-dev
https://golang.org/cl/4810059

src/pkg/runtime/proc.c

index ffaf44ddd8fb7ab2bb43d644f5d4ee358eae41dd..6d8f6990b2e64d489cd4c54c56eb6e0295cc451c 100644 (file)
@@ -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()) {