11 stable releases

2.2.0 Oct 18, 2023
2.1.1 Sep 25, 2023
2.1.0 Apr 7, 2023
2.0.0 Aug 4, 2020
1.0.1 May 28, 2020

#285 in Concurrency

Download history 470831/week @ 2024-01-08 521676/week @ 2024-01-15 566681/week @ 2024-01-22 694574/week @ 2024-01-29 528610/week @ 2024-02-05 522416/week @ 2024-02-12 518214/week @ 2024-02-19 552345/week @ 2024-02-26 566642/week @ 2024-03-04 565686/week @ 2024-03-11 581533/week @ 2024-03-18 577407/week @ 2024-03-25 600903/week @ 2024-04-01 606408/week @ 2024-04-08 631323/week @ 2024-04-15 601890/week @ 2024-04-22

2,468,716 downloads per month
Used in 4,714 crates (7 directly)

Apache-2.0 OR MIT

17KB
191 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.

Dependencies

~0–26MB
~352K SLoC