aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/crash_cgo_test.go
diff options
context:
space:
mode:
authorAustin Clements <austin@google.com>2017-06-06 18:37:59 -0400
committerAustin Clements <austin@google.com>2017-06-07 02:13:51 +0000
commit4e7067cde4a602e3a301500baac6cfbdebcffd97 (patch)
treeaac96d25303f47ba0bfaeb8a6a16b1c5742feb38 /src/runtime/crash_cgo_test.go
parentb5a0f7156845302040746ebcb71304f6cb03ba40 (diff)
downloadgo-4e7067cde4a602e3a301500baac6cfbdebcffd97.tar.gz
go-4e7067cde4a602e3a301500baac6cfbdebcffd97.zip
runtime: mark extra M's G as dead when not in use
Currently the extra Ms created for cgo callbacks have a corresponding G that's kept in syscall state with only a call to goexit on its stack. This leads to confusing output from runtime.NumGoroutines and in tracebacks: goroutine 17 [syscall, locked to thread]: runtime.goexit() .../src/runtime/asm_amd64.s:2197 +0x1 Fix this by putting this goroutine into state _Gdead when it's not in use instead of _Gsyscall. To keep the goroutine counts correct, we also add one to sched.ngsys while the goroutine is in _Gdead. The effect of this is as if the goroutine simply doesn't exist when it's not in use. Fixes #16631. Fixes #16714. Change-Id: Ieae08a2febd4b3d00bef5c23fd6ca88fb2bb0087 Reviewed-on: https://go-review.googlesource.com/45030 Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/runtime/crash_cgo_test.go')
-rw-r--r--src/runtime/crash_cgo_test.go9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/runtime/crash_cgo_test.go b/src/runtime/crash_cgo_test.go
index 3815cccfbc..70f1c1d16e 100644
--- a/src/runtime/crash_cgo_test.go
+++ b/src/runtime/crash_cgo_test.go
@@ -395,3 +395,12 @@ func TestRaceSignal(t *testing.T) {
t.Errorf("expected %q got %s", want, got)
}
}
+
+func TestCgoNumGoroutine(t *testing.T) {
+ t.Parallel()
+ got := runTestProg(t, "testprogcgo", "NumGoroutine")
+ want := "OK\n"
+ if got != want {
+ t.Errorf("expected %q got %v", want, got)
+ }
+}