From 98c5a56f0178db479c71fa76b5791ce2fcfc58b9 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Thu, 25 Apr 2019 22:39:56 -0700 Subject: [PATCH] runtime: account for callbacks in checkdead on Windows When a callback runs on a different thread in Windows, as in the runtime package test TestCallbackInAnotherThread, it will use the extra M. That can cause the test in checkdead to fail incorrectly. Check whether there actually is an extra M before expecting it. I think this is a general problem unrelated to timers. I think the test was passing previously because the timer goroutine was using an M. But I haven't proved that. This change seems correct, and it avoids the test failure when using the new timers on Windows. Updates #27707 Change-Id: Ieb31c04ff0354d6fae7e173b59bcfadb8b0464cd Reviewed-on: https://go-review.googlesource.com/c/go/+/174037 Reviewed-by: Keith Randall --- src/runtime/proc.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/runtime/proc.go b/src/runtime/proc.go index 1871d3b248..b8ee616eaa 100644 --- a/src/runtime/proc.go +++ b/src/runtime/proc.go @@ -4187,7 +4187,12 @@ func checkdead() { // for details.) var run0 int32 if !iscgo && cgoHasExtraM { - run0 = 1 + mp := lockextra(true) + haveExtraM := extraMCount > 0 + unlockextra(mp) + if haveExtraM { + run0 = 1 + } } run := mcount() - sched.nmidle - sched.nmidlelocked - sched.nmsys -- 2.48.1