runtime: fix races in stack scan

This fixes a hang during runtime.TestTraceStress.
It also fixes double-scan of stacks, which leads to
stack barrier installation failures.

Both of these have shown up as flaky failures on the dashboard.

Fixes #10941.

Change-Id: Ia2a5991ce2c9f43ba06ae1c7032f7c898dc990e0
Reviewed-on: https://go-review.googlesource.com/11089
Reviewed-by: Austin Clements <austin@google.com>
This commit is contained in:
Russ Cox 2015-06-16 19:20:18 -04:00
parent a2aaede366
commit 3c60e6e8cf
5 changed files with 61 additions and 116 deletions

View file

@ -756,13 +756,16 @@ func newstack() {
// be set and gcphasework will simply
// return.
}
gcphasework(gp)
if !gp.gcscandone {
scanstack(gp)
gp.gcscandone = true
}
gp.preemptscan = false
gp.preempt = false
casfrom_Gscanstatus(gp, _Gscanwaiting, _Gwaiting)
casgstatus(gp, _Gwaiting, _Grunning)
gp.stackguard0 = gp.stack.lo + _StackGuard
gp.preempt = false
gp.preemptscan = false // Tells the GC premption was successful.
gogo(&gp.sched) // never return
gogo(&gp.sched) // never return
}
// Act like goroutine called runtime.Gosched.