2018-08-30 12:18:55 +00:00
|
|
|
//@ run-pass
|
2021-12-03 15:32:51 +00:00
|
|
|
//@ needs-unwind
|
2016-02-11 11:34:41 +00:00
|
|
|
//@ ignore-emscripten no threads support
|
|
|
|
|
2019-01-26 16:14:49 +00:00
|
|
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
2015-12-25 19:00:40 +00:00
|
|
|
use std::panic;
|
|
|
|
use std::thread;
|
|
|
|
|
2019-01-26 16:14:49 +00:00
|
|
|
static A: AtomicUsize = AtomicUsize::new(0);
|
2015-12-25 19:00:40 +00:00
|
|
|
|
|
|
|
fn main() {
|
2016-05-24 21:24:44 +00:00
|
|
|
panic::set_hook(Box::new(|_| {
|
2015-12-25 19:00:40 +00:00
|
|
|
A.fetch_add(1, Ordering::SeqCst);
|
2016-05-24 21:24:44 +00:00
|
|
|
}));
|
2015-12-25 19:00:40 +00:00
|
|
|
|
|
|
|
let result = thread::spawn(|| {
|
2016-05-24 21:24:44 +00:00
|
|
|
let result = panic::catch_unwind(|| {
|
2015-12-25 19:00:40 +00:00
|
|
|
panic!("hi there");
|
|
|
|
});
|
|
|
|
|
2016-05-24 21:24:44 +00:00
|
|
|
panic::resume_unwind(result.unwrap_err());
|
2015-12-25 19:00:40 +00:00
|
|
|
}).join();
|
|
|
|
|
2016-05-06 23:32:18 +00:00
|
|
|
let msg = *result.unwrap_err().downcast::<&'static str>().unwrap();
|
2015-12-25 19:00:40 +00:00
|
|
|
assert_eq!("hi there", msg);
|
|
|
|
assert_eq!(1, A.load(Ordering::SeqCst));
|
|
|
|
}
|