1个不稳定版本
0.1.0 | 2021年1月5日 |
---|
#24 in #semaphore
26KB
465 行代码(不包括注释)
heliograph

太阳仪提供了对System V信号集的安全中等程度绑定。它公开了(大部分)其API,以便保持灵活性,因此在这个意义上是底层的。然而,它还保留了一个信号集的信号量,用于存储信号集引用计数,以便正确清理,因此它不是一个-sys crate,不应在其他不知道heliograph的“协议”的信号量用户之间使用。
lib.rs
:
对System V信号集的安全绑定
请注意,这些绑定将不会与由 heliograph
处理的信号量正常工作。尽管这不会导致未定义行为,但它可能会导致不希望的结果:由该库处理的信号集实际上没有 nsems
信号量,而是 nsems + 1
,其中额外的一个用于跟踪信号量的引用计数。
示例
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
依赖项
~1.5MB
~36K SLoC