#park #notify #thread #wake #condition

parking

Thread parking and unparking

8 stable releases

2.0.0 Aug 4, 2020
1.0.6 Jul 24, 2020
1.0.3 Jun 25, 2020
1.0.1 May 28, 2020

#243 in Concurrency

Download history 91195/week @ 2021-07-01 95026/week @ 2021-07-08 93034/week @ 2021-07-15 99022/week @ 2021-07-22 109016/week @ 2021-07-29 99550/week @ 2021-08-05 105431/week @ 2021-08-12 138447/week @ 2021-08-19 112081/week @ 2021-08-26 115652/week @ 2021-09-02 134579/week @ 2021-09-09 126090/week @ 2021-09-16 114267/week @ 2021-09-23 120347/week @ 2021-09-30 150039/week @ 2021-10-07 123866/week @ 2021-10-14

347,793 downloads per month
Used in 1,459 crates (5 directly)

Apache-2.0 OR MIT

14KB
142 lines

parking

Build License Cargo Documentation

Thread parking and unparking.

A parker is in either notified or unnotified state. Method park() blocks the current thread until the parker becomes notified and then puts it back into unnotified state. Method unpark() puts it into notified state.

Examples

use std::thread;
use std::time::Duration;
use parking::Parker;

let p = Parker::new();
let u = p.unparker();

// Notify the parker.
u.unpark();

// Wakes up immediately because the parker is notified.
p.park();

thread::spawn(move || {
    thread::sleep(Duration::from_millis(500));
    u.unpark();
});

// Wakes up when `u.unpark()` notifies and then goes back into unnotified state.
p.park();

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.

No runtime deps