#lock-free #smart-pointers #generic #performance #memory #building-block #reference-counting

xarc

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.

2 unstable releases

0.3.0 May 19, 2021
0.2.0 Sep 20, 2020
0.1.0 Sep 16, 2020

#1036 in Concurrency

MPL-2.0 license

17KB
285 lines

xarc

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(&current, &Xarc::null(), Ordering::AcqRel, Ordering::Acquire).unwrap();
assert_eq!(*loaded.maybe_deref().unwrap(), 42);

lib.rs:

xarc

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.

Dependencies

~255KB