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

57 lines
1.1 KiB
Rust
Raw Normal View History

//@ run-pass
//@ needs-unwind
2019-06-29 16:51:44 +01:00
#![allow(stable_features)]
2019-06-29 16:51:44 +01:00
#![allow(unused_must_use)]
//@ needs-threads
2018-07-23 03:14:42 +01:00
#![feature(std_panic)]
2015-12-17 23:51:55 -08:00
use std::panic;
use std::thread;
fn a() {
2016-03-15 20:38:58 -07: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-17 23:51:55 -08:00
}
fn b() {
2016-03-15 20:38:58 -07:00
panic::take_hook();
panic::take_hook();
panic::take_hook();
panic::take_hook();
panic::take_hook();
2015-12-17 23:51:55 -08:00
panic!();
}
fn c() {
2016-03-15 20:38:58 -07: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-17 23:51:55 -08: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();
}
}
}