#thread #signaling #bit #signal #wait #listener #signaler

waithandle

A library that makes signaling between threads a bit more ergonomic

4 releases (breaking)

0.4.0 May 26, 2020
0.3.0 Mar 18, 2020
0.2.0 Mar 17, 2020
0.1.0 Dec 12, 2019

#861 in Concurrency

MIT license

9KB
114 lines

Waithandle

A Rust library that makes signaling between threads a bit more ergonomic.

Uses Condvar and Mutex under the hood to block threads without consuming CPU time.

Usage

use std::time::Duration;

// Create the signaler and the listener
let (signaler, listener) = waithandle::new();

// Signal a thread
signaler.signal();

// Did someone signal us?
if listener.check() {
    println!("signal received");
}

// Wait for 5 seconds or until someone signals us
if listener.wait(Duration::from_secs(5)) {
    println!("signal received");
}

Running the example

> cargo run --example simple
Doing some work...
Doing some work...
Doing some work...
Doing some work...
Doing some work...
Signaling thread...
Joining thread...
Someone told us to exit!
Done!

Running benchmarks

> cargo bench

No runtime deps