mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
runtime: make NumGoroutine and Stack agree not to include system goroutines
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: I6bfe26a901de517728192cfb26a5568c4ef4fe47
Reviewed-on: https://go-review.googlesource.com/18343
Reviewed-by: Austin Clements <austin@google.com>
This commit is contained in:
parent
20d745c57c
commit
c5bafc8281
5 changed files with 47 additions and 1 deletions
|
|
@ -2162,6 +2162,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
|
||||
|
|
@ -2693,6 +2696,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 {
|
||||
|
|
@ -2885,7 +2891,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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue