diff options
| author | Russ Cox <rsc@golang.org> | 2016-01-06 21:16:01 -0500 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2016-01-13 01:46:01 +0000 |
| commit | fac8202c3ffdddf5d2b35a2c3620c1eb56018b9b (patch) | |
| tree | ec9ed1a66478563127a9faa17fe8764705692c6a /src/runtime/proc.go | |
| parent | 1e066cad1ba23f4064545355b8737e4762dd6838 (diff) | |
| download | go-fac8202c3ffdddf5d2b35a2c3620c1eb56018b9b.tar.xz | |
runtime: make NumGoroutine and Stack agree not to include system goroutines
[Repeat of CL 18343 with build fixes.]
Before, NumGoroutine counted system goroutines and Stack (usually) didn't show them,
which was inconsistent and confusing.
To resolve which way they should be consistent, it seems like
package main
import "runtime"
func main() { println(runtime.NumGoroutine()) }
should print 1 regardless of internal runtime details. Make it so.
Fixes #11706.
Change-Id: If26749fec06aa0ff84311f7941b88d140552e81d
Reviewed-on: https://go-review.googlesource.com/18432
Reviewed-by: Austin Clements <austin@google.com>
Run-TryBot: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src/runtime/proc.go')
| -rw-r--r-- | src/runtime/proc.go | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/runtime/proc.go b/src/runtime/proc.go index 545e134cc2..be1bb815d5 100644 --- a/src/runtime/proc.go +++ b/src/runtime/proc.go @@ -2167,6 +2167,9 @@ func goexit0(gp *g) { _g_ := getg() casgstatus(gp, _Grunning, _Gdead) + if isSystemGoroutine(gp) { + atomic.Xadd(&sched.ngsys, -1) + } gp.m = nil gp.lockedm = nil _g_.m.lockedg = nil @@ -2698,6 +2701,9 @@ func newproc1(fn *funcval, argp *uint8, narg int32, nret int32, callerpc uintptr gostartcallfn(&newg.sched, fn) newg.gopc = callerpc newg.startpc = fn.fn + if isSystemGoroutine(newg) { + atomic.Xadd(&sched.ngsys, +1) + } casgstatus(newg, _Gdead, _Grunnable) if _p_.goidcache == _p_.goidcacheend { @@ -2890,7 +2896,7 @@ func badunlockosthread() { } func gcount() int32 { - n := int32(allglen) - sched.ngfree + n := int32(allglen) - sched.ngfree - int32(atomic.Load(&sched.ngsys)) for i := 0; ; i++ { _p_ := allp[i] if _p_ == nil { |
