Skip to content

Commit

Permalink
[coop] Make sure suspend_count is positive in suspend request states
Browse files Browse the repository at this point in the history
* Fix bug in pulse transition - the suspend count was lost and incorrectly
  swapped to 0.
* finish_async_suspend transition - add assertions that the suspend count is
  positive. Try to catch incorrect states sooner.

Fixes mono#12235
  • Loading branch information
lambdageek committed Jan 2, 2019
1 parent 362b1a5 commit 66c9448
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion mono/utils/mono-threads-state-machine.c
Expand Up @@ -487,7 +487,7 @@ mono_threads_transition_request_pulse (MonoThreadInfo* info)
case STATE_BLOCKING_ASYNC_SUSPENDED:
if (!(suspend_count == 1))
mono_fatal_with_history ("suspend_count = %d, but should be == 1", suspend_count);
if (mono_atomic_cas_i32 (&info->thread_state, STATE_BLOCKING_SUSPEND_REQUESTED, raw_state) != raw_state)
if (mono_atomic_cas_i32 (&info->thread_state, build_thread_state (STATE_BLOCKING_SUSPEND_REQUESTED, suspend_count), raw_state) != raw_state)
goto retry_state_change;
trace_state_change ("PULSE", info, raw_state, STATE_BLOCKING_SUSPEND_REQUESTED, -1);
return PulseInitAsyncPulse; // Pulse worked and caller must do async pulse, thread pulses in BLOCKING
Expand Down Expand Up @@ -536,11 +536,15 @@ mono_threads_transition_finish_async_suspend (MonoThreadInfo* info)
return FALSE; //let self suspend wait

case STATE_ASYNC_SUSPEND_REQUESTED:
if (!(suspend_count > 0))
mono_fatal_with_history ("suspend_count = %d, but should be > 0", suspend_count);
if (mono_atomic_cas_i32 (&info->thread_state, build_thread_state (STATE_ASYNC_SUSPENDED, suspend_count), raw_state) != raw_state)
goto retry_state_change;
trace_state_change_sigsafe ("FINISH_ASYNC_SUSPEND", info, raw_state, STATE_ASYNC_SUSPENDED, 0, "");
return TRUE; //Async suspend worked, now wait for resume
case STATE_BLOCKING_SUSPEND_REQUESTED:
if (!(suspend_count > 0))
mono_fatal_with_history ("suspend_count = %d, but should be > 0", suspend_count);
if (mono_atomic_cas_i32 (&info->thread_state, build_thread_state (STATE_BLOCKING_ASYNC_SUSPENDED, suspend_count), raw_state) != raw_state)
goto retry_state_change;
trace_state_change_sigsafe ("FINISH_ASYNC_SUSPEND", info, raw_state, STATE_BLOCKING_ASYNC_SUSPENDED, 0, "");
Expand Down

0 comments on commit 66c9448

Please sign in to comment.