Created
November 12, 2016 21:34
-
-
Save savonarola/c98ae4f6f5265cbf1d3b213e30c55d85 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::{thread, time}; | |
fn watchdog<F, T>(f: F) -> () | |
where | |
F: Send + 'static + Fn() -> T, | |
T: Send + 'static | |
{ | |
thread::spawn(move||{ | |
loop { | |
let handle = thread::spawn(f); | |
match handle.join() { | |
Ok(_) => { println!("thread finished") } | |
Err(_) => { println!("thread panicked") } | |
} | |
} | |
}); | |
} | |
fn main() { | |
watchdog( | |
move||{ | |
thread::sleep(time::Duration::from_millis(1000)); | |
} | |
); | |
thread::sleep(time::Duration::from_millis(10000000)); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment