mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
runtime: attach mark workers to P after they park
Currently mark workers attach to their designated Ps before parking, either during initialization or after performing a phase transition. However, in both of these cases, it's possible that the mark worker is running on a different P than the one it attaches to. This is a problem, because as soon as the worker attaches to a P, that P's scheduler can execute the worker. If the worker hasn't yet parked on the P it's actually running on, this means the worker G will be running in two places at once. The most visible consequence of this is that once the first instance of the worker does park, it will clear g.m and the second instance will crash shortly when it tries to use g.m. Fix this by moving the attach to the gopark callback. At this point, the G is genuinely stopped and the callback is running on the system stack, so it's safe for another P's scheduler to pick up the worker G. Fixes #13363. Fixes #13978. Change-Id: If2f7c4a4174f9511f6227e14a27c56fb842d1cc8 Reviewed-on: https://go-review.googlesource.com/18761 Reviewed-by: Rick Hudson <rlh@golang.org> Reviewed-by: Russ Cox <rsc@golang.org> Run-TryBot: Austin Clements <austin@google.com>
This commit is contained in:
parent
73d590b4bd
commit
eb3b1830b0
2 changed files with 58 additions and 33 deletions
|
|
@ -3212,6 +3212,8 @@ func procresize(nprocs int32) *p {
|
|||
traceGoUnpark(p.gcBgMarkWorker, 0)
|
||||
}
|
||||
globrunqput(p.gcBgMarkWorker)
|
||||
// This assignment doesn't race because the
|
||||
// world is stopped.
|
||||
p.gcBgMarkWorker = nil
|
||||
}
|
||||
for i := range p.sudogbuf {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue