aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/proc_test.go
diff options
context:
space:
mode:
authorAustin Clements <austin@google.com>2017-06-16 16:21:12 -0400
committerAustin Clements <austin@google.com>2017-10-11 17:47:21 +0000
commit4f34a5291317fe959074fb40b85d9be242b8a2fc (patch)
tree366434d6858a14b2b92bdfa04100390a0eafd1ac /src/runtime/proc_test.go
parenteff2b2620db005cb58c266c0f25309d6f466cb25 (diff)
downloadgo-4f34a5291317fe959074fb40b85d9be242b8a2fc.tar.gz
go-4f34a5291317fe959074fb40b85d9be242b8a2fc.zip
runtime: terminate locked OS thread if its goroutine exits
runtime.LockOSThread is sometimes used when the caller intends to put the OS thread into an unusual state. In this case, we never want to return this thread to the runtime thread pool. However, currently exiting the goroutine implicitly unlocks its OS thread. Fix this by terminating the locked OS thread when its goroutine exits, rather than simply returning it to the pool. Fixes #20395. Change-Id: I3dcec63b200957709965f7240dc216fa84b62ad9 Reviewed-on: https://go-review.googlesource.com/46038 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/proc_test.go')
-rw-r--r--src/runtime/proc_test.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/runtime/proc_test.go b/src/runtime/proc_test.go
index 835b548742..c6ecc2a472 100644
--- a/src/runtime/proc_test.go
+++ b/src/runtime/proc_test.go
@@ -746,3 +746,20 @@ func TestLockOSThreadNesting(t *testing.T) {
}
}()
}
+
+func TestLockOSThreadExit(t *testing.T) {
+ testLockOSThreadExit(t, "testprog")
+}
+
+func testLockOSThreadExit(t *testing.T, prog string) {
+ output := runTestProg(t, prog, "LockOSThreadMain", "GOMAXPROCS=1")
+ want := "OK\n"
+ if output != want {
+ t.Errorf("want %s, got %s\n", want, output)
+ }
+
+ output = runTestProg(t, prog, "LockOSThreadAlt")
+ if output != want {
+ t.Errorf("want %s, got %s\n", want, output)
+ }
+}