arc-atomic-ref

Crates.ioarc-atomic-ref
lib.rsarc-atomic-ref
version1.0.0
sourcesrc
created_at2023-02-24 18:58:20.561857
updated_at2023-02-24 18:58:20.561857
descriptionarc-atomic-ref is a small library that wraps arc-swap in Arc so the atomic reference can be shared widely between many tasks/threads
homepage
repositoryhttps://github.com/bluecatengineering/arc-atomic-ref
max_upload_size
id793848
size7,867
Evan Cameron (leshow)

documentation

https://docs.rs/arc-atomic-ref

README

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);
Commit count: 3

cargo fmt