Skip to content

Instantly share code, notes, and snippets.

@savonarola
Created November 12, 2016 21:34
Show Gist options
  • Save savonarola/c98ae4f6f5265cbf1d3b213e30c55d85 to your computer and use it in GitHub Desktop.
Save savonarola/c98ae4f6f5265cbf1d3b213e30c55d85 to your computer and use it in GitHub Desktop.
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