2024-02-16 20:02:50 +00:00
|
|
|
//@ run-pass
|
|
|
|
|
//@ needs-unwind
|
2024-03-06 12:19:20 -08:00
|
|
|
//@ needs-threads
|
2018-08-31 15:02:01 +02:00
|
|
|
#![allow(stable_features)]
|
|
|
|
|
|
2018-07-23 03:14:42 +01:00
|
|
|
#![feature(std_panic)]
|
2015-12-17 23:51:55 -08:00
|
|
|
|
|
|
|
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
|
|
|
|
use std::panic;
|
|
|
|
|
use std::thread;
|
|
|
|
|
|
|
|
|
|
static A: AtomicUsize = AtomicUsize::new(0);
|
|
|
|
|
static B: AtomicUsize = AtomicUsize::new(0);
|
|
|
|
|
|
|
|
|
|
fn main() {
|
2016-03-15 20:38:58 -07:00
|
|
|
panic::set_hook(Box::new(|_| { A.fetch_add(1, Ordering::SeqCst); }));
|
|
|
|
|
let hook = panic::take_hook();
|
|
|
|
|
panic::set_hook(Box::new(move |info| {
|
2015-12-17 23:51:55 -08:00
|
|
|
B.fetch_add(1, Ordering::SeqCst);
|
2016-03-15 20:38:58 -07:00
|
|
|
hook(info);
|
|
|
|
|
}));
|
2015-12-17 23:51:55 -08:00
|
|
|
|
|
|
|
|
let _ = thread::spawn(|| {
|
|
|
|
|
panic!();
|
|
|
|
|
}).join();
|
|
|
|
|
|
|
|
|
|
assert_eq!(1, A.load(Ordering::SeqCst));
|
|
|
|
|
assert_eq!(1, B.load(Ordering::SeqCst));
|
|
|
|
|
}
|