#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

#462 in Memory management

Download history 68/week @ 2024-02-25 60/week @ 2024-03-03 37/week @ 2024-03-10 74/week @ 2024-03-17 72/week @ 2024-03-24 240/week @ 2024-03-31 91/week @ 2024-04-07 27/week @ 2024-04-14 68/week @ 2024-04-21 42/week @ 2024-04-28 11/week @ 2024-05-05 44/week @ 2024-05-12 15/week @ 2024-05-19 95/week @ 2024-05-26 281/week @ 2024-06-02 146/week @ 2024-06-09

537 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