From 7c54fdce3e68566e346b7999ef1ff98bb1977bab Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Fri, 4 Aug 2023 08:24:01 -0700 Subject: [PATCH] rt: pop at least one task from inject queue (#5908) When attempting to pull a batch of tasks from the injection queue, ensure we set the cap to at least one. --- tokio/src/runtime/scheduler/multi_thread/worker.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tokio/src/runtime/scheduler/multi_thread/worker.rs b/tokio/src/runtime/scheduler/multi_thread/worker.rs index 7db01f3c587..8f3181ffcc3 100644 --- a/tokio/src/runtime/scheduler/multi_thread/worker.rs +++ b/tokio/src/runtime/scheduler/multi_thread/worker.rs @@ -787,6 +787,10 @@ impl Core { cap, ); + // Take at least one task since the first task is returned directly + // and nto pushed onto the local queue. + let n = usize::max(1, n); + let mut synced = worker.handle.shared.synced.lock(); // safety: passing in the correct `inject::Synced`. let mut tasks = unsafe { worker.inject().pop_n(&mut synced.inject, n) };