5 releases
Uses old Rust 2015
0.1.4 | Feb 5, 2018 |
---|---|
0.1.3 | Jan 6, 2018 |
0.1.2 | Sep 27, 2017 |
0.1.1 | May 5, 2017 |
0.1.0 | May 5, 2017 |
#1132 in Concurrency
301 downloads per month
Used in 27 crates
(10 directly)
10KB
164 lines
atomic_immut
Atomic immutable value for Rust.
lib.rs
:
Atomic immutable value.
Examples
use std::sync::Arc;
use std::thread;
use atomic_immut::AtomicImmut;
let v = Arc::new(AtomicImmut::new(vec![0]));
{
let v = v.clone();
thread::spawn(move || {
let mut new = (&*v.load()).clone(); // Loads the immutable reference
new.push(1);
v.store(new); // Replaces the existing value
});
}
while v.load().len() == 1 {}
assert_eq!(&*v.load(), &vec![0, 1]);