#lock-free #reader-writer #cell #read #access #consistent #eventually

left-right-cell

A cell with lock-free concurrent read access

4 releases

0.1.3 Jan 20, 2024
0.1.2 Jul 26, 2022
0.1.1 Jul 26, 2022
0.1.0 Jul 26, 2022

#222 in Concurrency

Download history 257/week @ 2023-12-18 46/week @ 2023-12-25 216/week @ 2024-01-01 237/week @ 2024-01-08 156/week @ 2024-01-15 324/week @ 2024-01-22 277/week @ 2024-01-29 381/week @ 2024-02-05 417/week @ 2024-02-12 224/week @ 2024-02-19 167/week @ 2024-02-26 176/week @ 2024-03-04 217/week @ 2024-03-11 493/week @ 2024-03-18 118/week @ 2024-03-25 358/week @ 2024-04-01

1,189 downloads per month

MIT license

6KB
81 lines

left-right-cell

left-right-cell is a lockfree, eventually consistent cell created using the left-right crate. It allows readers to read from the cell without ever blocking while the writer might block when writing. This is achived by storing two copies of the data one for the readers and one for the writer.

let (mut w, r) = left_right_cell::new(false);

let t = std::thread::spawn(move || {
    loop {
        let value = r.get().unwrap();
        if *value {
            break;
        }
    }
});

w.set(true);
w.publish();
t.join().unwrap();
assert!(true);

lib.rs:

left-right-cell is a lockfree, eventually consistent cell created using the left-right crate. It allows readers to read from the cell without ever blocking while the writer might block when writing. This is achived by storing to copies of the data one for the readers and one for the writer.

Dependencies

~0.1–29MB
~360K SLoC