Skip to main content

Module concurrent

Module concurrent 

Source
Expand description

Thread-safe timer wheel: short-mutex wrapper around the base TimerWheel. Schedule + cancel + tick all serialize on a single Mutex because the critical sections are O(1) (or O(slot) on tick - bounded by entries-in-bucket, typically tiny).

Why a mutex and not a lock-free or sharded design: timer-wheel operations are short enough that a contended mutex still wins on tail latency vs the cache-line ping-pong of an atomic-list shape, provided callers don’t hold long external locks while inside a callback. The tick() method returns the fired values out of the critical section, so a caller can release the lock between retrieval and dispatch.

Tradeoff vs the base wheel: every operation pays a lock + unlock. For single-threaded workloads, prefer the base TimerWheel.

Structs§

ConcurrentTimerWheel