or how about this...?

This commit is contained in:
Eliza Weisman
2026-04-18 11:37:41 -07:00
parent 7c221a4f43
commit 9dc092aeaf
2 changed files with 7 additions and 13 deletions
@@ -150,6 +150,12 @@ impl Idle {
lock.idle.sleepers.contains(&worker_id)
}
/// Returns `true` if all other workers are currently parked.
pub(super) fn all_parked(&self) -> bool {
let state = State(self.state.fetch_add(0, SeqCst));
state.num_unparked() <= 1
}
fn notify_should_wakeup(&self) -> bool {
let state = State(self.state.fetch_add(0, SeqCst));
state.num_searching() == 0 && state.num_unparked() < self.num_workers
@@ -1352,8 +1352,6 @@ impl Handle {
let should_notify = if is_yield || !core.lifo_enabled {
core.run_queue
.push_back_or_overflow(task, self, &mut core.stats);
// Always notify another parked worker when pushing a yielded task
// to the main run queue if we are not currently parked.
true
} else {
// Push to the LIFO slot
@@ -1362,19 +1360,9 @@ impl Handle {
// to be pushed to the back of the run queue.
core.run_queue
.push_back_or_overflow(prev, self, &mut core.stats);
// We have pushed the previous LIFO task to the back of the run
// queue, so we should attempt to notify another worker if we
// are not currently parked.
true
} else {
// If the scheduled task was pushed to the LIFO slot and there
// is no other task previously in the slot, skip notifying
// another worker, so that we can preferentially poll the LIFO
// task next. It can still be stolen if another worker is
// searching. This reduces cross thread notifications, and
// reduces the chance of the LIFO task moving across threads if
// the next poll is short.
false
self.shared.idle.all_parked()
}
};