aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/runtime2.go
diff options
context:
space:
mode:
authorAustin Clements <austin@google.com>2017-06-15 10:51:15 -0400
committerAustin Clements <austin@google.com>2017-10-11 17:47:08 +0000
commit2595fe7fb6f272f9204ca3ef0b0c55e66fb8d90f (patch)
tree53c883492b86bf9313a11b78b038f431f7fe7ee6 /src/runtime/runtime2.go
parent9a9780a20d6987d462d97fa191de3c4a66980022 (diff)
downloadgo-2595fe7fb6f272f9204ca3ef0b0c55e66fb8d90f.tar.xz
runtime: don't start new threads from locked threads
Applications that need to manipulate kernel thread state are currently on thin ice in Go: they can use LockOSThread to prevent other goroutines from running on the manipulated thread, but Go may clone this manipulated state into a new thread that's put into the runtime's thread pool along with other threads. Fix this by never starting a new thread from a locked thread or a thread that may have been started by C. Instead, the runtime starts a "template thread" with a known-good state. If it then needs to start a new thread but doesn't know that the current thread is in a good state, it forwards the thread creation to the template thread. Fixes #20676. Change-Id: I798137a56e04b7723d55997e9c5c085d1d910643 Reviewed-on: https://go-review.googlesource.com/46033 Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/runtime/runtime2.go')
-rw-r--r--src/runtime/runtime2.go1
1 files changed, 1 insertions, 0 deletions
diff --git a/src/runtime/runtime2.go b/src/runtime/runtime2.go
index f56876fc63..325152aea4 100644
--- a/src/runtime/runtime2.go
+++ b/src/runtime/runtime2.go
@@ -533,6 +533,7 @@ type schedt struct {
nmidlelocked int32 // number of locked m's waiting for work
mcount int32 // number of m's that have been created
maxmcount int32 // maximum number of m's allowed (or die)
+ nmsys int32 // number of system m's not counted for deadlock
ngsys uint32 // number of system goroutines; updated atomically