tokio-rs / tokio

A runtime for writing reliable asynchronous applications with Rust. Provides I/O, networking, scheduling, timers, ...
https://tokio.rs
MIT License
26.59k stars 2.45k forks source link

runtime: move the task out of the lifo_slot in block_in_place #6596

Closed wathenjiang closed 4 months ago

wathenjiang commented 4 months ago

If we heavily call the spawn_blocking, there might be no available thread to run the current core. Except the task in the lifo_slot, all tasks in cores can be stolen, so we move the task from the lifo_slot to the run_queue before calling the spawn_blocking in the block_in_place.

This can prevent the starvation of the task in lifo_slot in edge cases.

carllerche commented 4 months ago

This change makes sense to me, thanks.