From cb945ba6ba23772336bf02fd2364c3df9e9233e0 Mon Sep 17 00:00:00 2001 From: Dmitriy Vyukov Date: Thu, 7 Mar 2013 21:39:59 +0400 Subject: [PATCH] =?utf8?q?runtime:=20fix=20deadlock=20The=20deadlock=20epi?= =?utf8?q?sodically=20occurs=20on=20misc/cgo/test/TestCthread.=20The=20pro?= =?utf8?q?blem=20is=20that=20starttheworld()=20leaves=20some=20P's=20with?= =?utf8?q?=20local=20work=20without=20M's.=20Then=20all=20active=20M's=20e?= =?utf8?q?nter=20into=20syscalls,=20but=20reject=20to=20wake=20another=20M?= =?utf8?q?'s=20due=20to=20the=20following=20check=20(both=20in=20entersysc?= =?utf8?q?allblock()=20and=20in=20retake()):=20if(p->runqhead=20=3D=3D=20p?= =?utf8?q?->runqtail=20&&=20=20=20=20=20=20=20=20=20runtime=C2=B7atomicloa?= =?utf8?q?d(&runtime=C2=B7sched.nmspinning)=20+=20=20=20=20=20=20=20=20=20?= =?utf8?q?runtime=C2=B7atomicload(&runtime=C2=B7sched.npidle)=20>=200)=20?= =?utf8?q?=20=20=20=20=20=20=20=20continue;?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit R=rsc CC=golang-dev https://golang.org/cl/7424054 --- src/pkg/runtime/proc.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/pkg/runtime/proc.c b/src/pkg/runtime/proc.c index 4ce0a718cd..d0f6745aa7 100644 --- a/src/pkg/runtime/proc.c +++ b/src/pkg/runtime/proc.c @@ -392,7 +392,7 @@ mhelpgc(void) void runtime·starttheworld(void) { - P *p; + P *p, *p1; M *mp; bool add; @@ -405,6 +405,7 @@ runtime·starttheworld(void) procresize(runtime·gomaxprocs); runtime·gcwaiting = 0; + p1 = nil; while(p = pidleget()) { // procresize() puts p's with work at the beginning of the list. // Once we reach a p without a run queue, the rest don't have one either. @@ -414,8 +415,9 @@ runtime·starttheworld(void) } mp = mget(); if(mp == nil) { - pidleput(p); - break; + p->link = p1; + p1 = p; + continue; } if(mp->nextp) runtime·throw("starttheworld: inconsistent mp->nextp"); @@ -428,6 +430,13 @@ runtime·starttheworld(void) } runtime·unlock(&runtime·sched); + while(p1) { + p = p1; + p1 = p1->link; + add = false; + newm(nil, p); + } + if(add) { // If GC could have used another helper proc, start one now, // in the hope that it will be available next time. -- 2.48.1