2018-08-30 07:18:55 -05:00
|
|
|
// run-pass
|
2021-12-03 09:32:51 -06:00
|
|
|
// needs-unwind
|
2018-08-31 08:02:01 -05:00
|
|
|
#![allow(stable_features)]
|
|
|
|
|
2016-08-08 18:39:37 -05:00
|
|
|
// ignore-emscripten no threads support
|
|
|
|
|
2018-07-22 21:14:42 -05:00
|
|
|
#![feature(std_panic)]
|
2015-12-18 01:51:55 -06: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 22:38:58 -05: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-18 01:51:55 -06:00
|
|
|
B.fetch_add(1, Ordering::SeqCst);
|
2016-03-15 22:38:58 -05:00
|
|
|
hook(info);
|
|
|
|
}));
|
2015-12-18 01:51:55 -06:00
|
|
|
|
|
|
|
let _ = thread::spawn(|| {
|
|
|
|
panic!();
|
|
|
|
}).join();
|
|
|
|
|
|
|
|
assert_eq!(1, A.load(Ordering::SeqCst));
|
|
|
|
assert_eq!(1, B.load(Ordering::SeqCst));
|
|
|
|
}
|