Skip to content

Implements a non-blocking synchronization primitive for lazy-initialized immutable references.

License

Notifications You must be signed in to change notification settings

andrewsonin/lazy_ref

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lazy_ref

Implements a non-blocking synchronization primitive for lazy-initialized immutable references.

Crates.io Documentation MIT licensed Build Status

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));

About

Implements a non-blocking synchronization primitive for lazy-initialized immutable references.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages