2022-03-09 15:27:28 +00:00
|
|
|
// run-pass
|
|
|
|
#![allow(unreachable_code)]
|
|
|
|
|
2022-03-09 17:10:48 +00:00
|
|
|
use std::sync::atomic::{AtomicBool, Ordering, AtomicUsize};
|
2022-03-09 15:27:28 +00:00
|
|
|
|
|
|
|
struct Print(usize);
|
|
|
|
|
|
|
|
impl Drop for Print {
|
|
|
|
fn drop(&mut self) {
|
2022-03-09 17:10:48 +00:00
|
|
|
println!("{}", self.0);
|
2022-03-09 15:27:28 +00:00
|
|
|
FOO[self.0].store(true, Ordering::Relaxed);
|
2022-03-09 17:10:48 +00:00
|
|
|
assert_eq!(BAR.fetch_sub(1, Ordering::Relaxed), self.0);
|
2022-03-09 15:27:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const A: Print = Print(0);
|
|
|
|
const B: Print = Print(1);
|
|
|
|
|
2022-03-09 17:10:48 +00:00
|
|
|
static FOO: [AtomicBool; 3] =
|
|
|
|
[AtomicBool::new(false), AtomicBool::new(false), AtomicBool::new(false)];
|
|
|
|
static BAR: AtomicUsize = AtomicUsize::new(2);
|
2022-03-09 15:27:28 +00:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
loop {
|
2022-03-09 17:10:48 +00:00
|
|
|
std::mem::forget(({ A }, B, Print(2), break));
|
2022-03-09 15:27:28 +00:00
|
|
|
}
|
|
|
|
for (i, b) in FOO.iter().enumerate() {
|
|
|
|
assert!(b.load(Ordering::Relaxed), "{} not set", i);
|
|
|
|
}
|
2022-03-09 17:10:48 +00:00
|
|
|
assert_eq!(BAR.fetch_add(1, Ordering::Relaxed), usize::max_value());
|
|
|
|
}
|