diff --git a/crossbeam-utils/tests/atomic_cell.rs b/crossbeam-utils/tests/atomic_cell.rs index 93be2bbba..a1d102210 100644 --- a/crossbeam-utils/tests/atomic_cell.rs +++ b/crossbeam-utils/tests/atomic_cell.rs @@ -336,8 +336,12 @@ fn issue_748() { #[test] fn issue_833() { use std::num::NonZeroU128; + use std::sync::atomic::{AtomicBool, Ordering}; use std::thread; + #[cfg(miri)] + const N: usize = 10_000; + #[cfg(not(miri))] const N: usize = 1_000_000; #[allow(dead_code)] @@ -350,15 +354,16 @@ fn issue_833() { Some(nonzero) => nonzero, None => unreachable!(), })); + static FINISHED: AtomicBool = AtomicBool::new(false); - thread::spawn(|| { + let handle = thread::spawn(|| { let cell = match &STATIC { Enum::NeverConstructed => unreachable!(), Enum::Cell(cell) => cell, }; let x = NonZeroU128::new(0xFFFF_FFFF_FFFF_FFFF_0000_0000_0000_0000).unwrap(); let y = NonZeroU128::new(0x0000_0000_0000_0000_FFFF_FFFF_FFFF_FFFF).unwrap(); - loop { + while !FINISHED.load(Ordering::Relaxed) { cell.store(x); cell.store(y); } @@ -369,4 +374,7 @@ fn issue_833() { unreachable!(":("); } } + + FINISHED.store(true, Ordering::Relaxed); + handle.join().unwrap(); }