From 0b5d55984fc939fdc35128342aa7cb34b0798de6 Mon Sep 17 00:00:00 2001 From: Dmitriy Vyukov Date: Sat, 6 Apr 2013 22:27:54 -0700 Subject: [PATCH] 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 --- src/pkg/runtime/proc.c | 7 +++++++ 1 file changed, 7 insertions(+) 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); }