From: Dmitriy Vyukov Date: Sun, 7 Apr 2013 05:27:54 +0000 (-0700) Subject: runtime: fix deadlock in network poller X-Git-Tag: go1.1rc2~156 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=0b5d55984fc939fdc35128342aa7cb34b0798de6;p=gostls13.git runtime: fix deadlock in network poller The invariant is that there must be at least one running P or a thread polling network. It was broken. Fixes #5216. R=golang-dev, bradfitz, r CC=golang-dev https://golang.org/cl/8459043 --- diff --git a/src/pkg/runtime/proc.c b/src/pkg/runtime/proc.c index 0a131871f3..018a453d62 100644 --- a/src/pkg/runtime/proc.c +++ b/src/pkg/runtime/proc.c @@ -875,6 +875,13 @@ handoffp(P *p) startm(p, false); return; } + // If this is the last running P and nobody is polling network, + // need to wakeup another M to poll network. + if(runtime·sched.npidle == runtime·gomaxprocs-1 && runtime·atomicload64(&runtime·sched.lastpoll) != 0) { + runtime·unlock(&runtime·sched); + startm(p, false); + return; + } pidleput(p); runtime·unlock(&runtime·sched); }