Skip to main content

Module sharded

Module sharded 

Source
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 🔒
ShardedCoord 🔒
State protected by ShardedImpl::coord. This mirrors LockedInner, except that the queue itself lives in the shards.
ShardedImpl 🔒

Constants§

NUM_SHARDS 🔒
Number of shards. Must be a power of two.