16 releases (4 breaking)

0.4.2 Jan 6, 2021
0.4.1 Jan 5, 2021
0.3.2 Jan 3, 2021
0.2.5 Jan 3, 2021
0.0.5 Dec 31, 2020

#128 in Concurrency

Download history 2/week @ 2021-06-26 3/week @ 2021-07-03 3/week @ 2021-07-10 22/week @ 2021-07-17 22/week @ 2021-07-24 41/week @ 2021-07-31 3/week @ 2021-08-07 41/week @ 2021-08-14 4/week @ 2021-08-21 1/week @ 2021-08-28 1/week @ 2021-09-04 1/week @ 2021-09-11 2/week @ 2021-09-18 20/week @ 2021-09-25 1/week @ 2021-10-02 21/week @ 2021-10-09

125 downloads per month
Used in faa_array_queue

MIT license

43KB
660 lines

peril

Latest version Documentation Lines of code MIT

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.

Usage

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), &registry);
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),
    }
}

License

Licensed under MIT license

Dependencies

~49KB