Permalink
Browse files

Call SleepEx in a loop in the Thread.Sleep () icall, to avoid a race …

…when the sleep is interrupted. Fixes #683519.
  • Loading branch information...
1 parent c399647 commit 648880d967fcdb976171d18e38ca65cdeeb0232b @vargaz vargaz committed Mar 30, 2011
Showing with 14 additions and 6 deletions.
  1. +14 −6 mono/metadata/threads.c
View
@@ -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;
+ }
+ }
}
}

0 comments on commit 648880d

Please sign in to comment.