[−][src]Crate parking
Thread parking and unparking.
This is a copy of the
park()
/unpark()
mechanism from
the standard library.
What is parking
Conceptually, each Parker
has a token which is initially not present:
-
The
Parker::park()
method blocks the current thread unless or until the token is available, at which point it automatically consumes the token. It may also return spuriously, without consuming the token. -
The
Parker::park_timeout()
method works the same asParker::park()
, but blocks until a timeout is reached. -
The
Parker::park_deadline()
method works the same asParker::park()
, but blocks until a deadline is reached. -
The
Parker::unpark()
andUnparker::unpark()
methods atomically make the token available if it wasn't already. Because the token is initially absent,Unparker::unpark()
followed byParker::park()
will result in the second call returning immediately.
Analogy with channels
Another way of thinking about Parker
is as a bounded
channel with capacity of 1.
Then, Parker::park()
is equivalent to blocking on a
receive operation, and Unparker::unpark()
is
equivalent to a non-blocking send operation.
Structs
Parker | Parks a thread. |
Unparker | Unparks a thread. |