3 releases (breaking)
0.4.0 | May 9, 2024 |
---|---|
0.3.0 | May 9, 2024 |
0.2.0 | May 8, 2024 |
0.1.0 |
|
#777 in Concurrency
49 downloads per month
12KB
106 lines
lazy_ref
Implements a non-blocking synchronization primitive for lazy-initialized immutable references.
Usage
Writing to a LazyRef
from separate threads:
use rayon::prelude::*;
use lazy_ref::LazyRef;
let lazy_ref = LazyRef::new();
let thread_ids: Vec<usize> = vec![1, 2, 3];
thread_ids.par_iter()
.for_each(
|id| {
let r = lazy_ref.get_or_init(|| id);
assert!(thread_ids.contains(r));
}
);
let x = lazy_ref.get().unwrap();
assert!(thread_ids.contains(x));
Dependencies
~110KB