#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

#426 in Memory management

Download history 38/week @ 2024-03-13 100/week @ 2024-03-20 113/week @ 2024-03-27 201/week @ 2024-04-03 57/week @ 2024-04-10 50/week @ 2024-04-17 45/week @ 2024-04-24 43/week @ 2024-05-01 29/week @ 2024-05-08 24/week @ 2024-05-15 24/week @ 2024-05-22 246/week @ 2024-05-29 174/week @ 2024-06-05 240/week @ 2024-06-12 237/week @ 2024-06-19 221/week @ 2024-06-26

993 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