← Lessons

quiz vs the machine

Platinum1820

Concurrency

The Work Stealing Scheduler Revisited

How idle worker threads grab tasks from busy peers to keep every core fed.

5 min read · advanced · beat Platinum to climb

Each worker owns a queue

A work stealing scheduler gives every worker thread its own deque, a double ended queue of tasks. A worker pushes new tasks onto one end and pops its own work from that same end, which keeps its hot tasks local and lock light.

Stealing from the other end

When a worker empties its own deque, it does not idle. It picks a busy peer and steals a task from the opposite end of that peer's deque. Using the opposite end matters:

  • Less contention because the owner and the thief rarely touch the same end at once.
  • Better locality since the owner keeps its newest, cache warm tasks while thieves take older ones.

Why it balances load

Stealing makes balancing happen lazily and only when needed. A core stays on its own work until it runs dry, then helps a backlogged neighbor. This self adjusts to uneven task sizes without a central dispatcher deciding placement up front. Modern async runtimes and fork join pools use this scheme to keep all cores busy under irregular load.

Key idea

Work stealing gives each worker a deque it uses locally and lets idle workers steal from the far end of busy peers, balancing load lazily with little contention.

Check yourself

Answer to earn rating on the learn ladder.

1. From which end of a busy peer's deque does an idle worker steal?

2. Why is work stealing good for irregular task sizes?