Expand description
OS-backed wait/wake primitives for IndexBus.
This crate provides thin wrappers around platform “wait on address” primitives for an aligned
u32:
- Linux: futex (
FUTEX_WAIT|PRIVATE/FUTEX_WAKE|PRIVATE) - Windows:
WaitOnAddress/WakeByAddressSingle/WakeByAddressAll
These are intended for blocking adapters and higher-level async integration.
§Feature flags
std(default): enablesstd::fmt::Displayandstd::error::ErrorforWaitError. The wait/wake functions themselves only depend oncore, but still require an OS.
§Correctness notes
These primitives are parking mechanisms, not a full synchronization protocol:
- Waits may return spuriously (a wake can unblock a waiter even if the value is still equal).
- Wakes are not queued; a wake that happens before a thread actually sleeps can be lost.
wait_u32_eqdoes not establish a happens-before edge for your data by itself.
Higher-level code should use the standard “sequence” pattern:
- Writer: update shared data, then
store(seq + 1, Ordering::Release), then callwake_*. - Reader:
load(Ordering::Acquire)and, if unchanged, callwait_u32_eqin a loop.
§Minimal usage
use core::time::Duration;
use indexbus_wake::{wait_u32_eq, wake_one};
use std::sync::atomic::{AtomicU32, Ordering};
let seq = AtomicU32::new(0);
let addr = &seq as *const AtomicU32 as *const u32;
// SAFETY: `addr` is aligned/valid for the call, and the location is mutated race-free via
// the `AtomicU32` at the same address.
unsafe {
// Typical reader-side pattern: re-check the condition in a loop around this call.
let _ = wait_u32_eq(addr, 0, Some(Duration::from_millis(10)));
}
seq.store(1, Ordering::Release);
unsafe { wake_one(addr) };Enums§
- Wait
Error - Errors returned by platform wait primitives.
Functions§
- wait_
u32_ ⚠eq - Wait while the 32-bit value at
addrequalsexpected. - wake_
all ⚠ - Wake all waiters blocked on
addr. - wake_
one ⚠ - Wake a single waiter blocked on
addr.