Tokio is the most widely used async runtime for Rust. When you write #[tokio::main] and await a few futures, Tokio decides which task runs on which thread, in what order, and for how long. If you have ever wondered why one task seems to starve others, why thread::sleep freezes your server, or why a single-threaded runtime is sometimes faster than a multi-threaded one, the answers live in the scheduler.
A task is a unit of async work: an async fn that Tokio polls, asking it to make progress until it hits an await and yields control. The scheduler is the part of Tokio that decides which task a worker thread polls next. The run queue, the cooperative scheduling budget, the I/O driver, and the blocking thread pool are the mechanisms behind those decisions, and each one maps to a concrete choice you can make in your own code.
The run queue: a LIFO slot, a local queue, and a global queue
Each worker thread in the multi-threaded runtime pulls tasks in a specific order: the LIFO slot first, then its own local queue, then the global queue, then by stealing from other workers’ queues.
The local queue is a FIFO (first in, first out) queue per worker. FIFO means tasks run in the order they were added. Tokio gives each worker its own local queue so threads do not contend on a single shared lock for every task submission. A shared global queue still exists because it guarantees fairness: when a task is spawned from outside the runtime, it goes to the global queue where any worker can pick it up.
The LIFO slot is the interesting part. LIFO means last in, first out. It is a single-slot optimization borrowed from Go. When a task spawns another task, the new task lands in the LIFO slot and runs first. This keeps recently created tasks on the same thread, which improves cache locality, and it cuts message-passing latency when two tasks talk to each other: the spawned task runs immediately instead of waiting behind unrelated work.
The LIFO slot costs fairness. When the slot is occupied, the worker moves the previous task to the back of the local run queue. Two tasks that keep spawning each other can in theory keep bouncing off the slot and delay everyone else. Tokio mitigates this with the cooperative budget described below, but it does not eliminate it.
Task stealing keeps idle workers busy
When a worker’s local queue and the global queue are both empty, the worker does not sit idle. It randomly picks another worker and steals half of that worker’s queued tasks. The LIFO slot is not stolen, because the owning worker still wants to run that task next.
This work-stealing design lets the multi-threaded runtime scale: no central dispatcher assigns work, so there is no single bottleneck. Each worker owns its queue, and stealing only happens when a worker has nothing left to do.
The tradeoff is that the scheduler is not aware of priority. It does not respect real-time scheduling; a worker can pull a background I/O task while a time-sensitive task waits. In a robotics project where a developer needed consistent timing, isolating critical tasks on a dedicated single-thread runtime and setting OS thread priorities eliminated 47ms of scheduler-induced drops. If you have tasks with hard timing requirements, give them their own runtime instead of expecting the work-stealing scheduler to protect them.
Cooperative scheduling: the 128-poll budget
Tokio cannot preempt a running task. Preemption means the OS forcibly stops a thread mid-execution. Tokio has no such mechanism, so it relies on cooperative scheduling: tasks must voluntarily yield by returning Pending from a poll.
A poll is Tokio asking the task for progress; the task returns Pending when it is waiting on something like a timer or a socket. To keep one long-running task from hogging a worker forever, the coop module gives each task a budget of 128 poll operations before Tokio forces it to return Pending and reschedule it.
This matters for CPU-bound loops inside async code. If you write a tight loop that computes without ever hitting an await, Tokio never gets a chance to poll other tasks, because the task never yields. The 128-poll budget only kicks in at poll boundaries, so a loop that does heavy computation inside a single poll can still block the worker. For that kind of work, use spawn_blocking or a dedicated CPU-bound executor.
The 61-tick rule keeps the I/O driver alive
The global queue poll interval is 61, a number Tokio copied from Go. Every 61 ticks, a worker checks the global queue first instead of its local queue. This prevents global tasks from starving behind a steady stream of locally spawned work.
The same 61-tick cadence protects the I/O driver. Every 61 ticks, the worker calls park_timeout with a zero timeout, which lets the I/O driver and timers run without the thread sleeping. The I/O driver is the component that watches sockets and other file descriptors for readiness. If a worker only ever ran tasks and never gave the driver a chance to check for I/O events, network connections would stall.
On Linux the I/O driver uses epoll, on macOS and BSD it uses kqueue, on Windows it uses IOCP, and on WASI it uses a special implementation. Mio provides the unified event-polling interface underneath. Each I/O resource is wrapped in a ScheduledIo and associated with a Mio token so the driver knows which socket became ready. Tokio also has experimental io_uring support on Linux, gated behind the tokio_unstable flag and several feature flags, which may reduce syscalls and support async file operations.
spawn_blocking: where blocking work goes
Async functions must not block, because a blocked worker thread cannot poll other tasks. When your code needs to do real blocking work, like reading a file synchronously or calling a C library, you hand the closure to spawn_blocking. Tokio runs it on a dedicated blocking thread, separate from the async worker pool.
Tokio spawns more blocking threads as needed, up to a configurable upper limit. The official docs describe the default as very large, since spawn_blocking is often used for I/O operations that cannot be async. One developer’s report puts the number at 512, but that figure is not confirmed by official documentation, so verify against your Tokio version before relying on it.
Three behaviors of spawn_blocking are easy to trip over. First, a task you spawn this way cannot be aborted once it starts; calling abort has no effect, and runtime shutdown waits for it indefinitely unless you use shutdown_timeout. Second, even the single-threaded runtime spawns additional OS threads for blocking operations; the single thread is only for async code. Third, calling block_on at the top level of a spawn_blocking task is generally supported, but it can deadlock if that task depends on other spawn_blocking tasks or on channel messages they send. The safe rule is that the task should be able to exit on its own even if every other thread is paused.
For CPU-bound work, spawn_blocking is the wrong tool. The blocking pool has no concept of load balancing beyond its thread count, so many CPU-heavy closures will just queue. Use a semaphore to limit concurrency, or hand the work to a specialized executor like rayon. That topic gets more detail in the article on running CPU-bound work on Tokio without blocking I/O.
What this means for your code
The most common mistake is blocking the runtime with a synchronous call. Calling thread::sleep inside async code parks the entire worker thread, so no other task on that thread runs. Use tokio::time::sleep instead, which yields to the scheduler.
A related surprise: the future you pass to Runtime::block_on, the one created by #[tokio::main], executes on the current thread. If you want to use the multi-threaded pool, you must explicitly spawn tasks with tokio::spawn. A reader who expects #[tokio::main] to distribute the main future across cores will see it run on one thread.
Lock choice follows the same logic. tokio::sync::Mutex parks the task and hands control to the scheduler when it contends, which is correct inside async code. For very short critical sections, std::sync::Mutex may be faster because it avoids the task-switch overhead, but if you hold it across an await, you risk blocking the worker while another task waits for the lock.
The multi-threaded runtime also has synchronization overhead. Every task handoff between workers involves atomic operations and cache misses, so in simple cases a single-threaded runtime is often faster. You need to benchmark your specific application; the benefit of multiple threads only shows up when there is enough concurrent work to amortize the coordination cost.
Finally, understand the cost of every abstraction you add. Timers, channels, and select! all involve polls, wake chains, and allocations. They are not free, even when the compiler optimizes some of them away. Before you reach for another Tokio primitive, ask whether the work actually needs it. For a grounding in how the whole async machinery fits together, the Tokio async/await implementation walkthrough is a good companion, and the Tokio versus async-std comparison helps if you are still choosing a runtime.