From bf3dce7ae3332f07965de20348286bd81d9ff739 Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Thu, 3 Aug 2023 14:35:49 -0700 Subject: [PATCH] rt: pop at least one task from inject queue 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) };