Crates.io | hzrd |
lib.rs | hzrd |
version | 0.1.0 |
source | src |
created_at | 2023-09-28 06:06:30.201943 |
updated_at | 2024-11-16 05:13:56.974014 |
description | Shared mutability containers based on hazard pointers |
homepage | |
repository | https://github.com/skogseth/hzrd/ |
max_upload_size | |
id | 985586 |
size | 86,334 |
Provides shared, mutable state by utilizing hazard pointers.
The core API of this crate is the HzrdCell, which provides an API reminiscent to that of the standard library's Cell-type. However, HzrdCell allows shared mutation across multiple threads.
use hzrd::HzrdCell;
let cell = HzrdCell::new(false);
std::thread::scope(|s| {
s.spawn(|| {
// Loop until the value is true ...
while !cell.get() {
std::hint::spin_loop();
}
// ... and then set it back to false!
cell.set(false);
});
s.spawn(|| {
// Set the value to true
cell.set(true);
// And then read the value!
// This might print either `true` or `false`
println!("{}", cell.get());
});
});
This project is licensed under the MIT license.