Skip to content

Commit

Permalink
Call SleepEx in a loop in the Thread.Sleep () icall, to avoid a race …
Browse files Browse the repository at this point in the history
…when the sleep is interrupted. Fixes #683519.
  • Loading branch information
vargaz committed Mar 30, 2011
1 parent c399647 commit 648880d
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions mono/metadata/threads.c
Original file line number Diff line number Diff line change
Expand Up @@ -1158,15 +1158,23 @@ void ves_icall_System_Threading_Thread_Sleep_internal(gint32 ms)

mono_thread_current_check_pending_interrupt ();

mono_thread_set_state (thread, ThreadState_WaitSleepJoin);
while (TRUE) {
mono_thread_set_state (thread, ThreadState_WaitSleepJoin);

res = SleepEx(ms,TRUE);
res = SleepEx(ms,TRUE);

mono_thread_clr_state (thread, ThreadState_WaitSleepJoin);
mono_thread_clr_state (thread, ThreadState_WaitSleepJoin);

if (res == WAIT_IO_COMPLETION) { /* we might have been interrupted */
MonoException* exc = mono_thread_execute_interruption (thread);
if (exc) mono_raise_exception (exc);
if (res == WAIT_IO_COMPLETION) { /* we might have been interrupted */
MonoException* exc = mono_thread_execute_interruption (thread);
if (exc) {
mono_raise_exception (exc);
} else {
// FIXME: !INFINITE
if (ms != INFINITE)
break;
}
}
}
}

Expand Down

0 comments on commit 648880d

Please sign in to comment.