mirror of
https://github.com/golang/go
synced 2024-11-19 15:24:46 -07:00
runtime: make (Un)LockOSThread doc more prescriptive
Right now users have to infer why they would want LockOSThread and when it may or may not be appropriate to call UnlockOSThread. This requires some understanding of Go's internal thread pool implementation, which is unfortunate. Improve the situation by making the documentation on these functions more prescriptive so users can figure out when to use them even if they don't know about the scheduler. Change-Id: Ide221791e37cb5106dd8a172f89fbc5b3b98fe32 Reviewed-on: https://go-review.googlesource.com/52871 Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
parent
4f34a52913
commit
0aef82aa4a
@ -3433,6 +3433,9 @@ func dolockOSThread() {
|
||||
// UnlockOSThread as to LockOSThread.
|
||||
// If the calling goroutine exits without unlocking the thread,
|
||||
// the thread will be terminated.
|
||||
//
|
||||
// A goroutine should call LockOSThread before calling OS services or
|
||||
// non-Go library functions that depend on per-thread state.
|
||||
func LockOSThread() {
|
||||
if atomic.Load(&newmHandoff.haveTemplateThread) == 0 {
|
||||
// If we need to start a new thread from the locked
|
||||
@ -3475,6 +3478,13 @@ func dounlockOSThread() {
|
||||
// calling goroutine to zero, it unwires the calling goroutine from
|
||||
// its fixed operating system thread.
|
||||
// If there are no active LockOSThread calls, this is a no-op.
|
||||
//
|
||||
// Before calling UnlockOSThread, the caller must ensure that the OS
|
||||
// thread is suitable for running other goroutines. If the caller made
|
||||
// any permanent changes to the state of the thread that would affect
|
||||
// other goroutines, it should not call this function and thus leave
|
||||
// the goroutine locked to the OS thread until the goroutine (and
|
||||
// hence the thread) exits.
|
||||
func UnlockOSThread() {
|
||||
_g_ := getg()
|
||||
if _g_.m.lockedExt == 0 {
|
||||
|
Loading…
Reference in New Issue
Block a user