#arc-swap #shared #wraps #thread #data #arc-t #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

#454 in Memory management

Download history 7/week @ 2024-01-29 23/week @ 2024-02-12 40/week @ 2024-02-19 73/week @ 2024-02-26 57/week @ 2024-03-04 36/week @ 2024-03-11 75/week @ 2024-03-18 73/week @ 2024-03-25 246/week @ 2024-04-01 83/week @ 2024-04-08 27/week @ 2024-04-15 69/week @ 2024-04-22

428 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