Expand description
L1: synchronization primitives for the pragma.core scheduler.
The only workspace crate where unsafe is allowed (see layers.toml,
DECISIONS.md #6). Rules: every block carries a // SAFETY: comment,
tests run under cargo +nightly miri test -p pragma_sync, and atomic protocols are
model-checked via RUSTFLAGS="--cfg loom" cargo test -p pragma_sync --release --lib --tests.
| Primitive | Purpose |
|---|---|
CountLatch | Wait for N events |
AtomicCounter | Task counter of a group; wait for zero while helping to run work |
current_label / TaskLabel | The thread’s task label for the panic hook and crash reports |
Scheduler building blocks (ArrivalCounter, Parker, scope, join_on_stack,
run_labeled and others) live in the hidden module __private: pragma_jobs uses them, they
change together with it and are not covered by semver guarantees (DECISIONS #42).
use pragma_sync::{AtomicCounter, CountLatch};
use std::sync::Arc;
let latch = Arc::new(CountLatch::new(2));
let workers: Vec<_> = (0..2)
.map(|_| {
let latch = Arc::clone(&latch);
std::thread::spawn(move || latch.count_down())
})
.collect();
latch.wait();
assert!(latch.is_released());
let pending = AtomicCounter::new(0);
pending.increment()?;
assert!(pending.decrement()); // reached zero
pending.wait(); // returns immediatelyStructs§
- Atomic
Counter - A counter of unfinished tasks that can be waited on until it reaches zero.
- Count
Latch - A count-down latch:
waitblocks until the counter reaches zero. - Task
Label - A task label (see
current_label).
Enums§
- Sync
Error - Errors of the synchronization primitives.
Functions§
- current_
label - Passes to
fthe label of the task currently running on this thread (None: no labels).