rust/src/test/ui/run-pass/panics/panic-handler-set-twice.rs

33 lines
914 B
Rust
Raw Normal View History

2015-12-18 07:51:55 +00: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.
// run-pass
2018-07-23 02:14:42 +00:00
#![feature(std_panic)]
2015-12-18 07:51:55 +00:00
// ignore-emscripten no threads support
2015-12-18 07:51:55 +00:00
use std::sync::atomic::{AtomicUsize, Ordering};
use std::panic;
use std::thread;
static A: AtomicUsize = AtomicUsize::new(0);
fn main() {
2016-03-16 03:38:58 +00:00
panic::set_hook(Box::new(|_| ()));
panic::set_hook(Box::new(|info| { A.fetch_add(1, Ordering::SeqCst); }));
2015-12-18 07:51:55 +00:00
let _ = thread::spawn(|| {
panic!();
}).join();
assert_eq!(1, A.load(Ordering::SeqCst));
}