[dev.garbage] runtime: Stop running gs during the GCscan phase.
Ensure that all gs are in a scan state when their stacks are being scanned.
LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/179160044
diff --git a/src/runtime/stack1.go b/src/runtime/stack1.go
index 78bcccc..57d0f8c 100644
--- a/src/runtime/stack1.go
+++ b/src/runtime/stack1.go
@@ -682,7 +682,12 @@
gothrow("runtime: g is running but p is not")
}
if gp.preemptscan {
+ for !castogscanstatus(gp, _Gwaiting, _Gscanwaiting) {
+ // Likely to be racing with the GC as it sees a _Gwaiting and does the stack scan.
+ // If so this stack will be scanned twice which does not change correctness.
+ }
gcphasework(gp)
+ casfrom_Gscanstatus(gp, _Gscanwaiting, _Gwaiting)
casgstatus(gp, _Gwaiting, _Grunning)
gp.stackguard0 = gp.stack.lo + _StackGuard
gp.preempt = false