]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: account for callbacks in checkdead on Windows
authorIan Lance Taylor <iant@golang.org>
Fri, 26 Apr 2019 05:39:56 +0000 (22:39 -0700)
committerIan Lance Taylor <iant@golang.org>
Mon, 29 Apr 2019 22:35:35 +0000 (22:35 +0000)
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 <khr@golang.org>
src/runtime/proc.go

index 1871d3b248644887d6328caea7dc3145f0ceb555..b8ee616eaa42eb203db968f00f160ef7bf1dba2a 100644 (file)
@@ -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