Thread control library

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:

  1. Check the thread execution status
  2. Interrupt thread execution
  3. Check the thread ended with panic
  4. 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);
}
6 Likes