Crates.io | xarc |
lib.rs | xarc |
version | 0.3.0 |
source | src |
created_at | 2020-09-16 07:26:03.33943 |
updated_at | 2021-05-19 06:39:15.338845 |
description | `xarc` provides atomically swappable atomically refcounted smart pointers as a safer building block for lockfree algorithms than raw atomic pointers. `Xarc` is comparable to `Arc` but with the additional ability to atomically be swapped into and out of `AtomicXarc`. `Xarc` is dereferenceable but cannot have its contents atomically swapped. `AtomicXarc` can have its contents atomically swapped but is not dereferenceable. |
homepage | |
repository | https://github.com/bazald/xarc/ |
max_upload_size | |
id | 289350 |
size | 49,800 |
xarc
provides atomically swappable atomically refcounted smart pointers
as a safer building block for lockfree algorithms than raw atomic pointers.
Xarc
is comparable to Arc
but with the additional ability to atomically
be swapped into and out of AtomicXarc
.
Xarc
is dereferenceable but cannot have its contents atomically swapped.
AtomicXarc
can have its contents atomically swapped but is not dereferenceable.
Here's a fairly minimal example.
use core::sync::atomic::Ordering;
use xarc::{AtomicXarc, Xarc};
let atomic = AtomicXarc::new(42);
let current = atomic.load(Ordering::Acquire);
let loaded = atomic.compare_exchange(¤t, &Xarc::null(), Ordering::AcqRel, Ordering::Acquire).unwrap();
assert_eq!(*loaded.maybe_deref().unwrap(), 42);