Skip to content

Commit 0838347

Browse files
committed
Change the scheduling to execute timeout callbacks first.
1 parent fdfd56b commit 0838347

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/thread.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,22 @@ impl<'mir, 'tcx: 'mir> ThreadManager<'mir, 'tcx> {
441441
}
442442
return Ok(SchedulingAction::Stop);
443443
}
444+
// At least for `pthread_cond_timedwait` we need to report timeout when
445+
// the function is called already after the specified time even if a
446+
// signal is received before the thread gets scheduled. Therefore, we
447+
// need to schedule all timeout callbacks before we continue regular
448+
// execution.
449+
//
450+
// Documentation:
451+
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cond_timedwait.html#
452+
if let Some(sleep_time) =
453+
self.timeout_callbacks.values().map(|info| info.call_time.get_wait_time()).min()
454+
{
455+
if sleep_time == Duration::new(0, 0) {
456+
return Ok(SchedulingAction::ExecuteTimeoutCallback);
457+
}
458+
}
459+
// No callbacks scheduled, pick a regular thread to execute.
444460
if self.threads[self.active_thread].state == ThreadState::Enabled
445461
&& !self.yield_active_thread
446462
{

0 commit comments

Comments
 (0)