Hi, folks!
I've created thread-control
library: https://github.com/DenisKolodin/thread-control
It's tiny, but useful library with missing thread control features:
- Check the thread execution status
- Interrupt thread execution
- Check the thread ended with
panic
- Share
Control
instance to control execution from many other threads
Example:
use std::thread;
use thread_control::*;
fn main() {
let (flag, control) = make_pair();
let handle = thread::spawn(move || {
while flag.alive() {
// It also can do `panic!("stop")` everywhere
}
});
assert_eq!(control.is_done(), false);
control.stop(); // Also you can `control.interrupt()` it
handle.join();
assert_eq!(control.is_interrupted(), false);
assert_eq!(control.is_done(), true);
}