Function parking_lot_core::parking_lot::park
source · pub unsafe fn park(
key: usize,
validate: impl FnOnce() -> bool,
before_sleep: impl FnOnce(),
timed_out: impl FnOnce(usize, bool),
park_token: ParkToken,
timeout: Option<Instant>,
) -> ParkResult
Expand description
Parks the current thread in the queue associated with the given key.
The validate
function is called while the queue is locked and can abort
the operation by returning false. If validate
returns true then the
current thread is appended to the queue and the queue is unlocked.
The before_sleep
function is called after the queue is unlocked but before
the thread is put to sleep. The thread will then sleep until it is unparked
or the given timeout is reached.
The timed_out
function is also called while the queue is locked, but only
if the timeout was reached. It is passed the key of the queue it was in when
it timed out, which may be different from the original key if
unpark_requeue
was called. It is also passed a bool which indicates
whether it was the last thread in the queue.
§Safety
You should only call this function with an address that you control, since you could otherwise interfere with the operation of other synchronization primitives.
The validate
and timed_out
functions are called while the queue is
locked and must not panic or call into any function in parking_lot
.
The before_sleep
function is called outside the queue lock and is allowed
to call unpark_one
, unpark_all
, unpark_requeue
or unpark_filter
, but
it is not allowed to call park
or panic.