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