waitx
waitx is a minimal synchronization utility for signaling readiness between threads using a lightweight flag, a condition variable, and optional backoff. It provides a flexible alternative to channels or more heavyweight synchronization primitives when you just need to wait for a single "ready" event.
Features
- Waiter: blocks until a flag is set, using backoff + condition variable.
- Notifier: sets the flag and notifies a waiting thread.
- Setter: sets the flag without notifying.
- Spectator: reads the state without modifying it.
- Lightweight and
no_std-compatible (withalloc). - Built on
parking_lotandcrossbeam-utils.
Usage
Add to your Cargo.toml:
[]
= "0.1"
Example
use thread;
use Waiter;
let waiter = default;
let notifier = waiter.notifier;
let handle = spawn;
sleep;
notifier.notify;
handle.join.unwrap;
When to Use
- Use waitx when you want a simple signaling mechanism:
- One thread signals readiness, another waits.
- A flag is reused multiple times with resets.
- You want fine control over notification vs. just setting state.
Crate Goals
- Minimal API
- Efficient signaling
- No channels or locks unless needed
- Readable and ergonomic code