From bee9120458dd3eb2c1486dd6c2344ec2c582f1b8 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 7 Jul 2024 09:19:32 +0200 Subject: [PATCH] once_lock: make test not take as long in Miri --- library/std/src/sync/once_lock.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/library/std/src/sync/once_lock.rs b/library/std/src/sync/once_lock.rs index f52b9e52c54..fe243550606 100644 --- a/library/std/src/sync/once_lock.rs +++ b/library/std/src/sync/once_lock.rs @@ -80,14 +80,21 @@ /// static LIST: OnceList = 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.into_iter().for_each(|handle| handle.join().unwrap()); +/// }); /// -/// for i in 0..=1000 { +/// for i in 0..LEN { /// assert!(LIST.contains(&i)); /// } ///