Skip to content

Commit

Permalink
Add test for issue 833
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed May 22, 2022
1 parent 80224bc commit cc5552b
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions crossbeam-utils/tests/atomic_cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,3 +330,43 @@ fn issue_748() {
let x = AtomicCell::new(Test::FieldLess);
assert_eq!(x.load(), Test::FieldLess);
}

// https://github.com/crossbeam-rs/crossbeam/issues/833
#[rustversion::since(1.40)] // const_constructor requires Rust 1.40
#[test]
fn issue_833() {
use std::num::NonZeroU128;
use std::thread;

const N: usize = 1_000_000;

#[allow(dead_code)]
enum Enum {
NeverConstructed,
Cell(AtomicCell<NonZeroU128>),
}

static STATIC: Enum = Enum::Cell(AtomicCell::new(match NonZeroU128::new(1) {
Some(nonzero) => nonzero,
None => unreachable!(),
}));

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 {
cell.store(x);
cell.store(y);
}
});

for _ in 0..N {
if let Enum::NeverConstructed = STATIC {
unreachable!(":(");
}
}
}

0 comments on commit cc5552b

Please sign in to comment.