#thread #control #execution #execution-status

thread-control

Rust library to control threads' execution/status

3 releases

Uses old Rust 2015

0.1.2 Apr 27, 2017
0.1.1 Sep 21, 2016
0.1.0 Sep 21, 2016

#616 in Concurrency

Download history 267/week @ 2023-11-16 189/week @ 2023-11-23 89/week @ 2023-11-30 250/week @ 2023-12-07 217/week @ 2023-12-14 75/week @ 2023-12-21 54/week @ 2023-12-28 79/week @ 2024-01-04 118/week @ 2024-01-11 235/week @ 2024-01-18 519/week @ 2024-01-25 325/week @ 2024-02-01 285/week @ 2024-02-08 142/week @ 2024-02-15 242/week @ 2024-02-22 400/week @ 2024-02-29

1,134 downloads per month
Used in 3 crates (2 directly)

MIT/Apache

7KB
67 lines

Thread-control library

Missing Rust features to control threads execution.

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(); // Also you can `control.interrupt()` it
    handle.join();
    assert_eq!(control.is_interrupted(), false);
    assert_eq!(control.is_done(), true);
}

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


lib.rs:

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);
}

No runtime deps