From 9dc092aeaf6fa2a491db7c8e1b0e4fc996f4a7bf Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Sat, 18 Apr 2026 11:37:41 -0700 Subject: [PATCH] or how about this...? --- tokio/src/runtime/scheduler/multi_thread/idle.rs | 6 ++++++ tokio/src/runtime/scheduler/multi_thread/worker.rs | 14 +------------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/tokio/src/runtime/scheduler/multi_thread/idle.rs b/tokio/src/runtime/scheduler/multi_thread/idle.rs index 834bc2b66..77cfb157e 100644 --- a/tokio/src/runtime/scheduler/multi_thread/idle.rs +++ b/tokio/src/runtime/scheduler/multi_thread/idle.rs @@ -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 diff --git a/tokio/src/runtime/scheduler/multi_thread/worker.rs b/tokio/src/runtime/scheduler/multi_thread/worker.rs index 42a52837f..29a4a2349 100644 --- a/tokio/src/runtime/scheduler/multi_thread/worker.rs +++ b/tokio/src/runtime/scheduler/multi_thread/worker.rs @@ -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() } };