Crate thread_control
source ·Expand description
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§
- Struct to control thread execution.
- Struct to check execution status of spawned thread.
Functions§
- Makes pair with connected flag and control.