matrix-authentication-service/.gear/predownloaded-development/vendor/parking
2026-03-07 01:41:31 +03:00
..
src added rust vendor 2026-03-07 01:41:31 +03:00
tests added rust vendor 2026-03-07 01:41:31 +03:00
.cargo-checksum.json added rust vendor 2026-03-07 01:41:31 +03:00
.cargo_vcs_info.json added rust vendor 2026-03-07 01:41:31 +03:00
Cargo.toml added rust vendor 2026-03-07 01:41:31 +03:00
Cargo.toml.orig added rust vendor 2026-03-07 01:41:31 +03:00
CHANGELOG.md added rust vendor 2026-03-07 01:41:31 +03:00
LICENSE-APACHE added rust vendor 2026-03-07 01:41:31 +03:00
LICENSE-MIT added rust vendor 2026-03-07 01:41:31 +03:00
LICENSE-THIRD-PARTY added rust vendor 2026-03-07 01:41:31 +03:00
README.md added rust vendor 2026-03-07 01:41:31 +03:00

parking

Build License Cargo Documentation

Thread parking and unparking.

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

This API is similar to thread::park() and Thread::unpark() from the standard library. The difference is that the state "token" managed by those functions is shared across an entire thread, and anyone can call thread::current() to access it. If you use park and unpark, but you also call a function that uses park and unpark internally, that function could cause a deadlock by consuming a wakeup that was intended for you. The Parker object in this crate avoids that problem by managing its own state, which isn't shared with unrelated callers.

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.