Skip to content

Commit 873cb8a

Browse files
authored
runtime: move task out of the lifo_slot in block_in_place (#6596)
1 parent 97bb47b commit 873cb8a

File tree

1 file changed

+9
-1
lines changed
  • tokio/src/runtime/scheduler/multi_thread

1 file changed

+9
-1
lines changed

tokio/src/runtime/scheduler/multi_thread/worker.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,11 +395,19 @@ where
395395
let cx = maybe_cx.expect("no .is_some() == false cases above should lead here");
396396

397397
// Get the worker core. If none is set, then blocking is fine!
398-
let core = match cx.core.borrow_mut().take() {
398+
let mut core = match cx.core.borrow_mut().take() {
399399
Some(core) => core,
400400
None => return Ok(()),
401401
};
402402

403+
// If we heavily call `spawn_blocking`, there might be no available thread to
404+
// run this core. Except for the task in the lifo_slot, all tasks can be
405+
// stolen, so we move the task out of the lifo_slot to the run_queue.
406+
if let Some(task) = core.lifo_slot.take() {
407+
core.run_queue
408+
.push_back_or_overflow(task, &*cx.worker.handle, &mut core.stats);
409+
}
410+
403411
// We are taking the core from the context and sending it to another
404412
// thread.
405413
take_core = true;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy