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 23:51:44 +08:00
#![allow(stable_features)]
2019-06-29 23:51:44 +08:00
#![allow(unused_must_use)]
// ignore-emscripten no threads support
2018-07-23 10:14:42 +08:00
#![feature(std_panic)]
2015-12-18 15:51:55 +08:00
use std::panic;
use std::thread;
fn a() {
2016-03-16 11:38:58 +08: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 15:51:55 +08:00
}
fn b() {
2016-03-16 11:38:58 +08:00
panic::take_hook();
panic::take_hook();
panic::take_hook();
panic::take_hook();
panic::take_hook();
2015-12-18 15:51:55 +08:00
panic!();
}
fn c() {
2016-03-16 11:38:58 +08: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 15: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();
}
}
}