#arc-swap #atomic-ref

arc-atomic-ref

arc-atomic-ref is a small library that wraps arc-swap in Arc<T> so the atomic reference can be shared widely between many tasks/threads

1 stable release

1.0.0 Feb 24, 2023

#424 in Memory management

Download history 394/week @ 2024-07-20 365/week @ 2024-07-27 334/week @ 2024-08-03 244/week @ 2024-08-10 261/week @ 2024-08-17 263/week @ 2024-08-24 456/week @ 2024-08-31 227/week @ 2024-09-07 394/week @ 2024-09-14 147/week @ 2024-09-21 186/week @ 2024-09-28 190/week @ 2024-10-05 246/week @ 2024-10-12 345/week @ 2024-10-19 98/week @ 2024-10-26 412/week @ 2024-11-02

1,112 downloads per month

MIT license

5KB

arc-atomic-ref

an AtomicRef is a smart pointer type that can be shared with many different threads of execution, while at the same time can be swapped out atomically with new data. In this way, it's similar to a lock-free RwLock or Mutex when you can replace the contained data rather than modify it.

use arc_atomic_ref::AtomicRef;
use std::sync::Arc;
let ptr = AtomicRef::new(1);
// share ptr with many threads with `clone`
// change its contained value, requires a new `Arc`
ptr.swap(Arc::new(2));
// all threads should see the change, use `.load()` to get the value
assert_eq!(**ptr.load(), 2);

lib.rs:

arc-atomic-ref

an AtomicRef is a smart pointer type that can be shared with many different threads of execution, while at the same time can be swapped out atomically with new data. In this way, it's similar to a lock-free RwLock or Mutex when you can replace the contained data rather than modify it.

use arc_atomic_ref::AtomicRef;
use std::sync::Arc;
let ptr = AtomicRef::new(1);
// share ptr with many threads with `clone`
// change its contained value, requires a new `Arc`
ptr.swap(Arc::new(2));
// all threads should see the change, use `.load()` to get the value
assert_eq!(**ptr.load(), 2);

Dependencies

~185KB