1 unstable release
0.1.0 | Jan 5, 2021 |
---|
#26 in #semaphore
26KB
465 lines
heliograph
Heliograph provides safe mid-level bindings to the System V semaphore sets. It exposes (most of) its API so that the flexibility could remain, and so in this sense is low-level. However, it also reserves one semaphore of the semaphore set for storing the semaphore set reference count for proper cleanup, and so is not a -sys crate and should not be used across other semaphore users that are not aware of heliograph's “protocol.”
Read the documentation for in-depth information, and see the Changelog for the changes between versions.
lib.rs
:
Safe bindings to System V semaphore sets
Note that these bindings will not work properly with semaphores
that are not handled by heliograph
. Even though it will not
result in Undefined Behavior, it may result in unwanted results:
semaphore sets handled by this library do not actually have
nsems
semaphores, but nsems + 1
, where the additional one is
used to track the reference count of the semaphore.
Examples
let file = tempfile::NamedTempFile::new().unwrap();
let key = Key::new(file.as_ref(), NonZeroU8::new(b'a').unwrap()).unwrap();
let sem = Semaphore::create(key, 1, Exclusive::No, Mode::from_bits(0o600).unwrap()).unwrap();
let sem = Arc::new(sem);
{
let sem = sem.clone();
std::thread::spawn(move || {
// Wait until the semaphore gets increased
sem.op(&[sem.at(0).remove(1)]).unwrap();
});
}
sem.op(&[sem.at(0).add(1)]).unwrap();
// Here the thread above is unblocked
Dependencies
~1.5MB
~36K SLoC