Skip to content

Commit

Permalink
Fix miri test
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed May 24, 2022
1 parent cf35e36 commit 012b0c2
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions crossbeam-utils/tests/atomic_cell.rs
Expand Up @@ -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)]
Expand All @@ -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);
}
Expand All @@ -369,4 +374,7 @@ fn issue_833() {
unreachable!(":(");
}
}

FINISHED.store(true, Ordering::Relaxed);
handle.join().unwrap();
}

0 comments on commit 012b0c2

Please sign in to comment.