rust/tests/ui/panics/panic-handler-flail-wildly.rs

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

57 lines
1.2 KiB
Rust
Raw Normal View History

//@ run-pass
//@ needs-unwind
2019-06-29 10:51:44 -05:00
#![allow(stable_features)]
2019-06-29 10:51:44 -05:00
#![allow(unused_must_use)]
//@ 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::panic;
use std::thread;
fn a() {
2016-03-15 22:38:58 -05:00
panic::set_hook(Box::new(|_| println!("hello yes this is a")));
panic::take_hook();
panic::set_hook(Box::new(|_| println!("hello yes this is a part 2")));
panic::take_hook();
2015-12-18 01:51:55 -06:00
}
fn b() {
2016-03-15 22:38:58 -05:00
panic::take_hook();
panic::take_hook();
panic::take_hook();
panic::take_hook();
panic::take_hook();
2015-12-18 01:51:55 -06:00
panic!();
}
fn c() {
2016-03-15 22:38:58 -05:00
panic::set_hook(Box::new(|_| ()));
panic::set_hook(Box::new(|_| ()));
panic::set_hook(Box::new(|_| ()));
panic::set_hook(Box::new(|_| ()));
panic::set_hook(Box::new(|_| ()));
panic::set_hook(Box::new(|_| ()));
2015-12-18 01:51:55 -06:00
panic!();
}
fn main() {
for _ in 0..10 {
let mut handles = vec![];
for _ in 0..10 {
handles.push(thread::spawn(a));
}
for _ in 0..10 {
handles.push(thread::spawn(b));
}
for _ in 0..10 {
handles.push(thread::spawn(c));
}
for handle in handles {
let _ = handle.join();
}
}
}