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

+9-1
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)