#ipc #semaphore #systemv #sysv


Medium-level bindings to System V semaphores

1 unstable release

0.1.0 Jan 5, 2021

#14 in #semaphore

Apache-2.0 OR BSD-3-Clause

465 lines

heliograph Crates.io Documentation

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.


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.


# use heliograph::*;
# use nix::sys::stat::Mode;
# use std::{num::NonZeroU8, sync::Arc};
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
// Here the thread above is unblocked


~18K SLoC