Work stealing and task scheduling
Relate owner/thief deque protocols to work, span, and the limits of parallel task scheduling.
On this page
The question for today
What you’ll understand
- Explain the asymmetric access pattern of a work-stealing deque.
- Calculate work/span lower bounds without treating them as runtime predictions.
- Use a binomial toy model to examine independent steal attempts and state its limits.
Parallelism is useful only when runnable work reaches idle processors without spending most of its time being scheduled. A work-stealing runtime lets a worker execute local tasks cheaply while idle workers try to take tasks from others. The deque protocol answers who owns a task; the scheduling policy answers where to look for work; the computation’s dependency graph limits how much work can run simultaneously. Keeping these layers separate prevents a fast queue microbenchmark from being mistaken for proof that an entire training pipeline will scale.
One owner and several thieves
In a Chase–Lev-style deque, one owner pushes and pops tasks at the bottom, while thieves try to remove tasks at the top. The asymmetric interface keeps common local operations cheap. When several items remain, the owner and a thief usually operate at different ends. When exactly one remains, both ends refer to the same task, so a coordinated atomic decision must ensure that only one participant claims it. Returning the same task twice can corrupt results even if the deque never crashes.
A growing circular array introduces another lifetime problem: a thief may still hold an older backing-array pointer while the owner resizes. Correct resizing must preserve accessible entries and retain old storage until no thief can use it. Memory ordering is part of the algorithm, especially around the last-item race and publication of the backing array. Translating sequential pseudocode into arbitrary relaxed C++ atomics is unsafe; use an implementation justified for the target language memory model.
Dependencies impose a lower bound
Represent a fixed computation as a directed acyclic graph of tasks. Total work T1 is its execution time on one ideal processor, and span T∞ is the length of its longest dependency path in the same cost units. With P identical processors, total work alone needs at least T1 divided by P time; no scheduler can execute a dependency chain faster than its span. The larger quantity is a lower bound, even before accounting for task creation, cache misses, synchronization, or interference.
Randomized work-stealing analysis gives an expected work-plus-span bound for a specified scheduler and fully strict computations. That theorem is not an equality for a particular run, and its hidden constants are not measured scheduling overhead. Arbitrary blocking tasks, external I/O, resource constraints, and general dependency graphs need their own analysis. Increasing the processor count beyond the computation’s average parallelism leaves a substantial span bottleneck; changing the dependency structure may matter more than choosing a different victim-selection policy.
Randomness helps distribute attempts, not guarantee fairness
Uniform random victim selection spreads idle workers across potential sources of tasks. For intuition, suppose each attempt independently succeeds with a fixed probability p. Then the count of successes in n attempts is binomial, and the chance of finding nothing is the probability of zero successes. Actual attempts can be dependent because deques change, workers collide, and successful steals change the future distribution. The simple model therefore cannot establish a production scheduler’s fairness, tail latency, or speedup.
In the probability lab, first predict how zero successes changes when p rises from one quarter to one half while n stays fixed. Then increase the trial count and inspect the exact binomial bars. These controls represent an explicitly independent, fixed-probability toy experiment, not a trace of workers manipulating deques. For real scheduling, also choose task grain carefully: very small tasks amplify enqueue, steal, and wakeup costs, while very large tasks can leave idle workers unable to share a long running task.
Work it through
Read a work/span budget correctly
An idealized fully strict computation has T1=1,200 milliseconds of total work and T∞=80 milliseconds of span. Consider eight identical processors, ignoring all overhead only for the lower-bound calculation.
The work lower bound is 1,200/8=150 milliseconds. The span lower bound is 80 milliseconds, so every valid execution takes at least max(150,80)=150 milliseconds under the stated cost model.
Average parallelism is 1,200/80=15. Eight processors are below that average, but this fact does not guarantee perfect utilization at every instant in the dependency graph.
A 150-millisecond execution would give speedup 1,200/150=8. Any overhead or imperfect scheduling increases runtime, so eight is a speedup ceiling here, not a measured or promised result.
The calculation establishes a 150-millisecond lower bound. Substituting the numbers into a big-O theorem does not yield an exact runtime such as 150+80 milliseconds.
The living notebook
Explore the model
Interactive lab · probability
A toy batch of independent steal attempts
Use success probability p and trial count n to inspect an exact binomial distribution. Predict the zero-success bar before changing either control.
- Mean · np
- 5
- Variance · np(1−p)
- 2.5
- Total probability
- 1
These are exact binomial probabilities for independent trials with one fixed success probability. Playback tours the distribution; it does not resample outcomes. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forIndependent fixed-probability attempts are a teaching assumption. Real workers contend over changing deques, so this model does not predict scheduler throughput or fairness.
Pause & reason
Check your understanding
Your turn
Try it yourself
Under the independent-attempt toy model, p=1/4 and n=4. What is the probability of zero successful attempts? Separately, if T1=600 ms and T∞=100 ms, can 16 ideal processors complete the computation in 40 ms?
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
For the probability multiply four failure probabilities. For runtime compare both work and span lower bounds.
Compare with the solution
Zero successes has probability (3/4)^4=81/256, about 31.64%. That is only the specified toy experiment. For scheduling, the work bound is 600/16=37.5 ms but the span bound is 100 ms, so runtime is at least 100 ms. Forty milliseconds is impossible under this dependency graph even with zero scheduling overhead.
Keep the idea
Take it with you
- A deque’s claim protocol and a scheduler’s policy solve different problems.
- Work and span bound ideal speedup but do not predict wall-clock runtime.
- State independence assumptions when using probability to reason about steal attempts.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.