Crates.io | peril |
lib.rs | peril |
version | 0.4.2 |
source | src |
created_at | 2020-12-28 23:46:29.661002 |
updated_at | 2021-01-06 03:42:01.142263 |
description | Fast and safe Hazard pointers for Rust. |
homepage | https://github.com/junkerjorg/peril |
repository | https://github.com/junkerjorg/peril |
max_upload_size | |
id | 328501 |
size | 43,816 |
Peril is fast and safe Hazard pointer implementation for Rust. Peril uses Chunks of 32 HazardRecords to quickly mark a pointer as protected. This is less efficent than other implementations that expose thread IDs to the user API, but it also frees the user from having to keep track of all active threads in the system.
Add these lines to your Cargo.toml
:
[dependencies]
peril = "0.4"
than use the HazardPointers in your lock-free update loop:
use peril::{HazardRegistry, HazardValue, HazardRecord, HazardPointer, Ordering};
let registry = HazardRegistry::default();
let hp = HazardPointer::new(HazardValue::boxed(0), ®istry);
let mut record = HazardRecord::default();
loop {
let scope = hp.protect(&mut record);
let new = *(scope.as_ref().unwrap()) + 1;
match scope.compare_exchange(HazardValue::boxed(new), Ordering::Relaxed, Ordering::Relaxed)
{
Ok(old) =>
{
assert!(old.as_ref().unwrap() == &0);
break;
}
Err(_) => assert!(false),
}
}
Licensed under MIT license