]> Cypherpunks repositories - gostls13.git/commit
runtime: attach mark workers to P after they park
authorAustin Clements <austin@google.com>
Wed, 20 Jan 2016 03:45:37 +0000 (22:45 -0500)
committerAustin Clements <austin@google.com>
Wed, 27 Jan 2016 02:13:53 +0000 (02:13 +0000)
commiteb3b1830b01fca572fcdd9c95aeb8090e6c09497
tree9b3703083c11b9e4dd03a0b999c99d29223e80b2
parent73d590b4bd3e4dbf48613a09db938bf2fe03a1aa
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>
src/runtime/mgc.go
src/runtime/proc.go