Skip to content

Commit

Permalink
Check if the thread is blocked before waking them up
Browse files Browse the repository at this point in the history
  • Loading branch information
tiif committed Aug 24, 2024
1 parent 3c4e484 commit 4fe8136
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/concurrency/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 3 additions & 1 deletion src/shims/unix/linux/epoll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,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(())
}
Expand Down

0 comments on commit 4fe8136

Please sign in to comment.