rust/src/test/run-pass/panic-handler-flail-wildly.rs

60 lines
1.5 KiB
Rust
Raw Normal View History

2015-12-18 01:51:55 -06:00
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(panic_handler, std_panic)]
// ignore-emscripten no threads support
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();
}
}
}