pub enum WaitStrategy {
BusySpin,
YieldSpin,
BackoffSpin,
Adaptive {
spin_iters: u32,
yield_iters: u32,
},
MonitorWait {
addr: *const u8,
},
MonitorWaitFallback,
}Expand description
Strategy for blocking recv() and SubscriberGroup::recv().
All variants are no_std compatible — no OS thread primitives required.
| Strategy | Latency | CPU usage | Best for |
|---|---|---|---|
BusySpin | Lowest (~0 ns wakeup) | 100% core | Dedicated, pinned cores |
YieldSpin | Low (~30 ns on x86) | High | Shared cores, SMT |
BackoffSpin | Medium (exponential) | Decreasing | Background consumers |
Adaptive | Auto-scaling | Varies | General purpose |
MonitorWait | Near-zero (~30 ns on Intel) | Near-zero | Intel Alder Lake+ |
Variants§
BusySpin
Pure busy-spin with no PAUSE instruction. Minimum wakeup latency but consumes 100% of one CPU core. Use on dedicated, pinned cores.
YieldSpin
Spin with core::hint::spin_loop() (PAUSE on x86, YIELD on ARM)
between iterations. Yields the CPU pipeline to the SMT sibling
and reduces power consumption vs BusySpin.
BackoffSpin
Exponential backoff spin. Starts with bare spins, then escalates to PAUSE-based spins with increasing delays. Good for consumers that may be idle for extended periods without burning a full core.
Adaptive
Three-phase escalation: bare spin for spin_iters iterations,
then PAUSE-spin for yield_iters, then repeated PAUSE bursts.
Fields
MonitorWait
UMONITOR/UMWAIT on Intel (Tremont+, Alder Lake+) or WFE on ARM.
On x86_64 with WAITPKG support: UMONITOR sets up a monitored
address range, UMWAIT puts the core into an optimized C0.1/C0.2
state until a write to the monitored cache line wakes it. Near-zero
power consumption with ~30 ns wakeup latency.
Falls back to YieldSpin on x86 CPUs without WAITPKG support.
On aarch64: uses SEVL+WFE (identical to YieldSpin).
addr must point to the stamp field of the slot being waited on.
Use WaitStrategy::monitor_wait to construct safely from an
AtomicU64 reference. For callers that cannot provide an address,
use MonitorWaitFallback.
§Safety (of direct construction)
Constructing this variant directly with an arbitrary pointer can
cause hardware faults on WAITPKG-capable CPUs. Prefer the safe
constructor WaitStrategy::monitor_wait.
Fields
MonitorWaitFallback
Like MonitorWait but without an explicit address.
On x86_64 with WAITPKG: falls back to TPAUSE (timed wait in
C0.1 state) for low-power waiting without address monitoring.
On aarch64: SEVL+WFE. On other x86: PAUSE.
Implementations§
Source§impl WaitStrategy
impl WaitStrategy
Sourcepub fn monitor_wait(stamp: &AtomicU64) -> Self
pub fn monitor_wait(stamp: &AtomicU64) -> Self
Safely construct a MonitorWait from
an AtomicU64 reference (typically a slot’s stamp field).
Trait Implementations§
Source§impl Clone for WaitStrategy
impl Clone for WaitStrategy
Source§fn clone(&self) -> WaitStrategy
fn clone(&self) -> WaitStrategy
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for WaitStrategy
impl Debug for WaitStrategy
Source§impl Default for WaitStrategy
impl Default for WaitStrategy
Source§impl PartialEq for WaitStrategy
impl PartialEq for WaitStrategy
impl Copy for WaitStrategy
impl Eq for WaitStrategy
impl Send for WaitStrategy
impl StructuralPartialEq for WaitStrategy
impl Sync for WaitStrategy
Auto Trait Implementations§
impl Freeze for WaitStrategy
impl RefUnwindSafe for WaitStrategy
impl Unpin for WaitStrategy
impl UnsafeUnpin for WaitStrategy
impl UnwindSafe for WaitStrategy
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.