Crates.io | left-right-cell |
lib.rs | left-right-cell |
version | 0.1.3 |
source | src |
created_at | 2022-07-26 15:13:06.233771 |
updated_at | 2024-01-20 16:58:22.907375 |
description | A cell with lock-free concurrent read access. |
homepage | https://github.com/Kl4rry/left-right-cell |
repository | https://github.com/Kl4rry/left-right-cell |
max_upload_size | |
id | 633237 |
size | 5,069 |
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);