]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: ensure _Grunning Gs have a valid g.m and g.m.p
authorAustin Clements <austin@google.com>
Tue, 16 Apr 2019 01:46:43 +0000 (21:46 -0400)
committerAustin Clements <austin@google.com>
Fri, 25 Oct 2019 16:59:39 +0000 (16:59 +0000)
We already claim on the documentation for _Grunning that this is case,
but execute transitions to _Grunning before assigning g.m. Fix this
and make the documentation even more explicit.

For #10958, #24543, but also a good cleanup.

Change-Id: I1eb0108e7762f55cfb0282aca624af1c0a15fe56
Reviewed-on: https://go-review.googlesource.com/c/go/+/201440
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
src/runtime/proc.go
src/runtime/runtime2.go

index 4814a5fc8777d3f2718860030df81f33c6ae476a..524d75e3c7a8648f586663c20a7e8e7b8506c57d 100644 (file)
@@ -2177,6 +2177,10 @@ func gcstopm() {
 func execute(gp *g, inheritTime bool) {
        _g_ := getg()
 
+       // Assign gp.m before entering _Grunning so running Gs have an
+       // M.
+       _g_.m.curg = gp
+       gp.m = _g_.m
        casgstatus(gp, _Grunnable, _Grunning)
        gp.waitsince = 0
        gp.preempt = false
@@ -2184,8 +2188,6 @@ func execute(gp *g, inheritTime bool) {
        if !inheritTime {
                _g_.m.p.ptr().schedtick++
        }
-       _g_.m.curg = gp
-       gp.m = _g_.m
 
        // Check whether the profiler needs to be turned on or off.
        hz := sched.profilehz
index aebc9af06fc1826a616361846398db3090119d88..c5023027be09ca6096f1de597fe13df24ae538ea 100644 (file)
@@ -40,7 +40,7 @@ const (
 
        // _Grunning means this goroutine may execute user code. The
        // stack is owned by this goroutine. It is not on a run queue.
-       // It is assigned an M and a P.
+       // It is assigned an M and a P (g.m and g.m.p are valid).
        _Grunning // 2
 
        // _Gsyscall means this goroutine is executing a system call.