]> Cypherpunks repositories - gostls13.git/commit
runtime: don't start new threads from locked threads
authorAustin Clements <austin@google.com>
Thu, 15 Jun 2017 14:51:15 +0000 (10:51 -0400)
committerAustin Clements <austin@google.com>
Wed, 11 Oct 2017 17:47:08 +0000 (17:47 +0000)
commit2595fe7fb6f272f9204ca3ef0b0c55e66fb8d90f
tree53c883492b86bf9313a11b78b038f431f7fe7ee6
parent9a9780a20d6987d462d97fa191de3c4a66980022
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>
src/runtime/proc.go
src/runtime/runtime2.go