Go to file
John Nunley 2aa2aece0f
v2.2.0
Signed-off-by: John Nunley <dev@notgull.net>
2023-10-17 19:18:35 -07:00
.github feat: Implement From<Unparker> for Waker 2023-10-07 21:54:29 -07:00
src feat: Implement From<Unparker> for Waker 2023-10-07 21:54:29 -07:00
tests Implement loom version of parking (#8) 2022-10-16 08:56:29 -07:00
.gitignore Initial commit 2020-05-16 16:13:43 +02:00
CHANGELOG.md v2.2.0 2023-10-17 19:18:35 -07:00
Cargo.toml v2.2.0 2023-10-17 19:18:35 -07:00
LICENSE-APACHE Add license 2020-05-16 16:14:37 +02:00
LICENSE-MIT Add license 2020-05-16 16:14:37 +02:00
LICENSE-THIRD-PARTY Add licensing information 2020-07-20 10:02:01 +02:00
README.md Update license badge to match Cargo.toml 2021-02-14 13:37:00 +09:00

README.md

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.