]> git.proxmox.com Git - rustc.git/blame - src/test/run-pass/panic-handler-flail-wildly.rs
Imported Upstream version 1.9.0+dfsg1
[rustc.git] / src / test / run-pass / panic-handler-flail-wildly.rs
CommitLineData
9cc50fc6
SL
1// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2// file at the top-level directory of this distribution and at
3// http://rust-lang.org/COPYRIGHT.
4//
5// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8// option. This file may not be copied, modified, or distributed
9// except according to those terms.
10#![feature(panic_handler, std_panic)]
11
7453a54e
SL
12// ignore-emscripten no threads support
13
9cc50fc6
SL
14use std::panic;
15use std::thread;
16
17fn a() {
54a0048b
SL
18 panic::set_hook(Box::new(|_| println!("hello yes this is a")));
19 panic::take_hook();
20 panic::set_hook(Box::new(|_| println!("hello yes this is a part 2")));
21 panic::take_hook();
9cc50fc6
SL
22}
23
24fn b() {
54a0048b
SL
25 panic::take_hook();
26 panic::take_hook();
27 panic::take_hook();
28 panic::take_hook();
29 panic::take_hook();
9cc50fc6
SL
30 panic!();
31}
32
33fn c() {
54a0048b
SL
34 panic::set_hook(Box::new(|_| ()));
35 panic::set_hook(Box::new(|_| ()));
36 panic::set_hook(Box::new(|_| ()));
37 panic::set_hook(Box::new(|_| ()));
38 panic::set_hook(Box::new(|_| ()));
39 panic::set_hook(Box::new(|_| ()));
9cc50fc6
SL
40 panic!();
41}
42
43fn main() {
44 for _ in 0..10 {
45 let mut handles = vec![];
46 for _ in 0..10 {
47 handles.push(thread::spawn(a));
48 }
49 for _ in 0..10 {
50 handles.push(thread::spawn(b));
51 }
52 for _ in 0..10 {
53 handles.push(thread::spawn(c));
54 }
55 for handle in handles {
56 let _ = handle.join();
57 }
58 }
59}