rust/tests/ui/panics/panic-handler-chain.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

30 lines
666 B
Rust
Raw Normal View History

//@ run-pass
//@ needs-unwind
//@ needs-threads
#![allow(stable_features)]
2018-07-23 02:14:42 +00:00
#![feature(std_panic)]
2015-12-18 07:51:55 +00: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-16 03:38:58 +00: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 07:51:55 +00:00
B.fetch_add(1, Ordering::SeqCst);
2016-03-16 03:38:58 +00:00
hook(info);
}));
2015-12-18 07:51:55 +00:00
let _ = thread::spawn(|| {
panic!();
}).join();
assert_eq!(1, A.load(Ordering::SeqCst));
assert_eq!(1, B.load(Ordering::SeqCst));
}