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

#271 in Concurrency

Download history 428571/week @ 2023-12-14 283784/week @ 2023-12-21 316428/week @ 2023-12-28 460729/week @ 2024-01-04 477423/week @ 2024-01-11 577930/week @ 2024-01-18 653161/week @ 2024-01-25 573454/week @ 2024-02-01 526551/week @ 2024-02-08 513843/week @ 2024-02-15 546009/week @ 2024-02-22 568019/week @ 2024-02-29 556784/week @ 2024-03-07 572413/week @ 2024-03-14 585925/week @ 2024-03-21 473810/week @ 2024-03-28

2,297,748 downloads per month
Used in 4,620 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–29MB
~359K SLoC