]> Cypherpunks repositories - gostls13.git/commit
runtime: mark extra M's G as dead when not in use
authorAustin Clements <austin@google.com>
Tue, 6 Jun 2017 22:37:59 +0000 (18:37 -0400)
committerAustin Clements <austin@google.com>
Wed, 7 Jun 2017 02:13:51 +0000 (02:13 +0000)
commit4e7067cde4a602e3a301500baac6cfbdebcffd97
treeaac96d25303f47ba0bfaeb8a6a16b1c5742feb38
parentb5a0f7156845302040746ebcb71304f6cb03ba40
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>
src/runtime/crash_cgo_test.go
src/runtime/proc.go
src/runtime/testdata/testprogcgo/numgoroutine.go [new file with mode: 0644]