Work stealing¶
Category: Scheduling · Status: stub
One line: Each worker thread keeps its own queue of tasks, and an idle worker takes tasks from a busy worker's queue, balancing the load without one central queue.
Also called: work-stealing scheduler.
How it connects¶
flowchart LR
n_async_runtime["Async runtime (executor and reactor)"]
n_fork_join["Fork-join"]
n_parallel_iterators["Parallel iterators and streams"]
n_scheduling_policy["Scheduling policy"]
n_work_stealing["Work stealing"]
n_async_runtime -->|uses| n_work_stealing
n_fork_join -->|uses| n_work_stealing
n_parallel_iterators -->|uses| n_work_stealing
n_work_stealing -->|is a| n_scheduling_policy
classDef center stroke-width:3px
class n_work_stealing center
classDef outside stroke-dasharray: 4 3
class n_async_runtime,n_fork_join,n_parallel_iterators,n_scheduling_policy outside
- Is a kind of: Scheduling policy
- Is used by: Async runtime (executor and reactor), Fork-join, Parallel iterators and streams
- See also: Thread pool and executor
In each language¶
| Rust | Tokio's multi-thread scheduler ↗ and Rayon's join ↗ both use work stealing |
| Java | ForkJoinPool ↗, and Executors.newWorkStealingPool ↗ |
| C# | The default TaskScheduler ↗ gives thread-pool threads local work queues, and an idle thread steals from another's |
Where to read more¶
- In the books: Concurrency in Go, Katherine Cox-Buday — ch. 6, 'Goroutines and the Go Runtime' → 'Work Stealing'
- In the books: Async Rust, Maxwell Flitton, Caroline Morton — ch. 3, 'Building Our Own Async Queues' → 'Task Stealing'
- In the books: The Art of Multiprocessor Programming, Maurice Herlihy, Nir Shavit — ch. 16, 'Futures, Scheduling, and Work Distribution' → 'Work-Stealing Dequeues'
- Notes: work-stealing based task scheduler ↗
- Reference: Wikipedia: Work stealing ↗