diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-07-07 14:22:03 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-07 14:22:03 +0200 |
| commit | b564c510c1b794cfb2e59ef64d14ffcdc22db6f5 (patch) | |
| tree | 4e8b7a8690e2b1023e198c91b5efeb8b731218b0 | |
| parent | 1ee6345b7b76416ca9cf4eacdb74d9590563c53f (diff) | |
| parent | bee9120458dd3eb2c1486dd6c2344ec2c582f1b8 (diff) | |
| download | rust-b564c510c1b794cfb2e59ef64d14ffcdc22db6f5.tar.gz rust-b564c510c1b794cfb2e59ef64d14ffcdc22db6f5.zip | |
Rollup merge of #127447 - RalfJung:once_lock_miri, r=joboet
once_lock: make test not take as long in Miri Allocating 1000 list elements takes a while (`@zachs18` reported >5min), so let's reduce the iteration count when running in Miri. Unfortunately due to this clever `while let i @ 0..LEN =` thing, the count needs to be a constants, and constants cannot be shadowed, so we need to use another trick to hide the `cfg!(miri)` from the docs. (I think this loop condition may be a bit too clever, it took me a bit to decipher. Ideally this would be `while let i = ... && i < LEN`, but that is not stable yet.)
| -rw-r--r-- | library/std/src/sync/once_lock.rs | 19 |
1 files 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 @@ 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)); /// } /// |
