Expand description
SharedCondvar: cross-process condition variable built on top
of CrossProcessWaker.
Classic Mesa-style condvar interface: waiters check a user-owned
predicate, park if not satisfied, and resume when a notifier
advances the predicate AND calls notify_*. The substrate uses
a monotonic generation counter so each wait parks at
target = current_gen + 1; every notify_* bumps the generation
and fires wake_(one_)up_to(new_gen), which wakes parked waiters
whose target <= new_gen.
§Cross-process semantics
Two processes mmap the same condvar base; both call wait /
notify_* directly. On Linux the wake call crosses the process
boundary via SHARED futex (keyed by inode + offset, so two
different mmaps of the same file page DO match). On Windows /
macOS the primitive runs intra-process via WaitOnAddress /
spin fallback.
§Intra-process sharing: use Arc::clone, NOT create+open
Within ONE process, share a single SharedCondvar through
Arc<SharedCondvar> + Arc::clone. Calling create and then
open on the same path in the same process produces two
independent mmaps with different virtual-address ranges aliased
to the same file pages. Windows WaitOnAddress is keyed by
virtual address, so a notify_* on the second handle does NOT
reach a wait on the first handle - the wake hashtable lookup
misses on the differing virtual address. Linux SHARED futex
keys by the underlying file page, which works across separate
mmaps, but the rule “use one Arc<SharedCondvar> per process”
is cross-platform safe.
The open constructor is exclusively for joiners in SEPARATE
processes that need to find the file the creator already
initialised.
§Predicate ownership
The condvar does NOT own the predicate atom; the caller passes
a closure that returns the current predicate value. This matches
parking_lot::Condvar::wait_while semantics and lets the same
condvar guard predicates held in any cross-process atom
(SharedAtomicU32, a field in a SharedCell, an offset into
an MMF struct, etc.).
Structs§
- Shared
Condvar - Cross-process condition variable. Mesa-style: callers re-check
the predicate after each wake. Internally backed by one
CrossProcessWakerplus a generation counter in mmap.
Enums§
- Condvar
Error - Errors returned by
SharedCondvaroperations.