Crate thread_control [−] [src]
Library to control thread execution.
Usage example:
use std::thread; use thread_control::*; fn main() { let (flag, control) = make_pair(); let handle = thread::spawn(move || { while flag.alive() { } }); assert_eq!(control.is_done(), false); control.stop(); handle.join(); assert_eq!(control.is_interrupted(), false); assert_eq!(control.is_done(), true); }
Interrupt example:
use std::thread; use thread_control::*; fn main() { let (flag, control) = make_pair(); let handle = thread::spawn(move || { while flag.alive() { } }); control.interrupt(); handle.join(); assert_eq!(control.is_interrupted(), true); assert_eq!(control.is_done(), true); }
Panics example:
use std::thread; use thread_control::*; fn main() { let (flag, control) = make_pair(); let handle = thread::spawn(move || { while flag.alive() { panic!("PANIC!"); } }); handle.join(); assert_eq!(control.is_interrupted(), true); assert_eq!(control.is_done(), true); }
Structs
Control |
Struct to control thread execution. |
Flag |
Struct to check execution status of spawned thread. |
Functions
make_pair |
Makes pair with connected flag and control. |