Skip to main content

Crate pragma_sync

Crate pragma_sync 

Source
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.

PrimitivePurpose
CountLatchWait for N events
AtomicCounterTask counter of a group; wait for zero while helping to run work
current_label / TaskLabelThe 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 immediately

Structs§

AtomicCounter
A counter of unfinished tasks that can be waited on until it reaches zero.
CountLatch
A count-down latch: wait blocks until the counter reaches zero.
TaskLabel
A task label (see current_label).

Enums§

SyncError
Errors of the synchronization primitives.

Functions§

current_label
Passes to f the label of the task currently running on this thread (None: no labels).