[threading] Implement 'pulse' transition for two-phase STW (#11708)
commitbe9a2f630313e60d02739a5db0d83fc0f5d69490
authorAleksey Kliger (λgeek) <akliger@gmail.com>
Fri, 16 Nov 2018 17:47:45 +0000 (16 12:47 -0500)
committerGitHub <noreply@github.com>
Fri, 16 Nov 2018 17:47:45 +0000 (16 12:47 -0500)
tree8bc658a19e4d1a156a079f4c76872641dc80b181
parent30ad7cde21487fe5d17b386edf2f4d0d431f61f0
[threading] Implement 'pulse' transition for two-phase STW (#11708)

* [threading] Add `pulse` transition and begin_pulse_resume_and_request_suspension operation.

A `pulse` atomically resumes a preemptively suspended GC Safe thread and
requests that it suspend again.

If the thread reaches a GC Safe -> GC Unsafe transition, it will self-suspend.
If it doesn't, another iteration of the 'mop up' STW phase will async suspend
it again.

* [threading] Use pulse_resume_and_request_suspension in STW

With non-hybrid suspend, a pulse is just a resume.

With hybrid suspend, a `pulse` is a combination of a resume of a preemptively
suspended GC Unsafe thread and a request that it suspend again - as if we
atomically resumed the thread and then applied the initial phase of two-phase
suspend again.  If the now-running thread comes to a GC Safe -> GC Unsafe
transition it will suspend.  If not, we will preemptively suspend it again
during the mop-up phase.

The important thing is that we don't want the thread to transition to GC Unsafe
again: if it does so, it may try to take a lock that some other
async-suspended thread is holding, and it will never reach a safepoint ---
exactly the situation that two-phase suspend is supposed to solve.

* [threads] Add mono_threads_is_multiphase_stw_enabled

Flip the logic in mono_thread_info_begin_pulse_resume_and_request_suspension
mono/metadata/sgen-stw.c
mono/utils/mono-threads-coop.h
mono/utils/mono-threads-state-machine.c
mono/utils/mono-threads.c
mono/utils/mono-threads.h