runtime: make NumGoroutine wait for system goroutines to register
commit9fc13e64afe560d4e6397c692920f828450e4808
authorian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 22 Jun 2017 15:46:47 +0000 (22 15:46 +0000)
committerian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 22 Jun 2017 15:46:47 +0000 (22 15:46 +0000)
tree6a99bb0ecaa8b80fff1f3d04929533bbc7d22048
parent50aca7c7511112b9520d0a7b67f2c34fb8e3822f
runtime: make NumGoroutine wait for system goroutines to register

    In libgo system goroutines register themselves after they start.
    That means that there is a small race between the goroutine being
    seen by the scheduler and the scheduler knowing that the goroutine
    is a system goroutine. That in turn means that runtime.NumGoroutines
    can overestimate the number of goroutines at times.

    This patch fixes the overestimate by counting the number of system
    goroutines waiting to start, and pausing NumGoroutines until those
    goroutines have all registered.

    This is kind of a lot of mechanism for this not very important
    problem, but I couldn't think of a better approach.

    The test for this is TestNumGoroutine in runtime/proc_test.go.
    The test is not currently run, but it will be soon.

    Reviewed-on: https://go-review.googlesource.com/46457

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@249565 138bc75d-0d04-0410-961f-82ee72b054a4
gcc/go/gofrontend/MERGE
libgo/go/runtime/debug.go
libgo/go/runtime/mfinal.go
libgo/go/runtime/mgc.go
libgo/go/runtime/proc.go
libgo/go/runtime/time.go