once_lock: make test not take as long in Miri

This commit is contained in:
Ralf Jung 2024-07-07 09:19:32 +02:00
parent 3bec61736a
commit bee9120458
1 changed files with 13 additions and 6 deletions

View File

@ -80,14 +80,21 @@ use crate::sync::Once;
/// 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);
/// # const LEN: u32 = if cfg!(miri) { 50 } else { 1000 };
/// # /*
/// const LEN: u32 = 1000;
/// # */
/// thread::scope(|s| {
/// for _ in 0..thread::available_parallelism().unwrap().get() {
/// s.spawn(|| {
/// while let i @ 0..LEN = 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 {
/// for i in 0..LEN {
/// assert!(LIST.contains(&i));
/// }
///