Expand description
A sharded queue for the blocking pool’s tasks.
Tasks live in NUM_SHARDS queues, each with its own mutex. Spawners push
to a shard chosen via the thread-local RNG; workers pop by scanning the
shards, starting from one derived from their worker id. A mask tracks which
shards have tasks so scans rarely lock empty shards.
Worker lifecycle (thread spawning, parking/waking, timeouts, shutdown) is
coordinated by the coord mutex + condvar, using the same claim
protocol as the default single-mutex queue. Unlike that queue, coord is
held only for the claim-or-spawn decision and for a worker’s transition
to idle — never around queue operations or task execution — so spawners
and workers contend mostly on 1/NUM_SHARDS of a shard lock each.
Structs§
- Shard 🔒
- Sharded
Coord 🔒 - State protected by
ShardedImpl::coord. This mirrorsLockedInner, except that the queue itself lives in the shards. - Sharded
Impl 🔒
Constants§
- NUM_
SHARDS 🔒 - Number of shards. Must be a power of two.