1
2
3use std::any::Any;
8use std::thread;
9use std::io::prelude::*;
10use std::io::stderr;
11use std::panic::{self, AssertUnwindSafe};
12
13pub fn halt_unwinding<F, R>(func: F) -> thread::Result<R>
18where
19 F: FnOnce() -> R,
20{
21 panic::catch_unwind(AssertUnwindSafe(func))
22}
23
24pub fn resume_unwinding(payload: Box<dyn Any + Send>) -> ! {
25 panic::resume_unwind(payload)
26}
27
28pub struct AbortIfPanic;
29
30fn aborting() {
31 let _ = writeln!(&mut stderr(), "Rayon: detected unexpected panic; aborting");
32}
33
34impl Drop for AbortIfPanic {
35 fn drop(&mut self) {
36 aborting();
37 ::std::process::abort(); }
39}