pub struct OnceList<T> { /* private fields */ }Expand description
use std::sync::{atomic::{AtomicU32, Ordering}};
use std::thread;
use once_list::OnceList;
// Let's exercise this new Sync append-only list by doing a little counting
static LIST: OnceList<u32> = OnceList::new();
static COUNTER: AtomicU32 = AtomicU32::new(0);
let vec = (0..thread::available_parallelism().unwrap().get()).map(|_| thread::spawn(|| {
while let i @ 0..1000 = COUNTER.fetch_add(1, Ordering::Relaxed) {
LIST.push(i);
}
})).collect::<Vec<thread::JoinHandle<_>>>();
vec.into_iter().for_each(|handle| handle.join().unwrap());
for i in 0..1000 {
assert!(LIST.contains(&i));
}Implementations§
Trait Implementations§
impl<T: Eq> Eq for OnceList<T>
impl<T> StructuralPartialEq for OnceList<T>
Auto Trait Implementations§
impl<T> !Freeze for OnceList<T>
impl<T> RefUnwindSafe for OnceList<T>where
T: RefUnwindSafe + UnwindSafe,
impl<T> Send for OnceList<T>where
T: Send,
impl<T> Sync for OnceList<T>
impl<T> Unpin for OnceList<T>where
T: Unpin,
impl<T> UnwindSafe for OnceList<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more