Check if the thread is blocked before waking them up

This commit is contained in:
tiif 2024-08-25 01:05:20 +08:00
parent 8f178e4812
commit 7aff711013
2 changed files with 13 additions and 1 deletions

View file

@ -578,6 +578,10 @@ impl<'tcx> ThreadManager<'tcx> {
self.threads[thread_id].state.is_terminated()
}
fn has_blocked_on_epoll(&self, thread_id: ThreadId) -> bool {
self.threads[thread_id].state.is_blocked_on(BlockReason::Epoll)
}
/// Have all threads terminated?
fn have_all_terminated(&self) -> bool {
self.threads.iter().all(|thread| thread.state.is_terminated())
@ -1137,6 +1141,12 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
this.machine.threads.enable_thread(thread_id);
}
#[inline]
fn has_blocked_on_epoll(&self, thread_id: ThreadId) -> bool {
let this = self.eval_context_ref();
this.machine.threads.has_blocked_on_epoll(thread_id)
}
#[inline]
fn active_thread_stack<'a>(&'a self) -> &'a [Frame<'tcx, Provenance, FrameExtra<'tcx>>] {
let this = self.eval_context_ref();

View file

@ -600,7 +600,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
waiter.sort();
waiter.dedup();
for thread_id in waiter {
this.unblock_thread(thread_id, BlockReason::Epoll)?;
if this.has_blocked_on_epoll(thread_id) {
this.unblock_thread(thread_id, BlockReason::Epoll)?;
}
}
Ok(())
}