Function parking_lot::park
[−]
[src]
pub unsafe fn park(key: usize, validate: &mut FnMut() -> bool, before_sleep: &mut FnMut(), timed_out: &mut FnMut(usize, UnparkResult), timeout: Option<Instant>) -> bool
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 an UnparkResult
which
indicates whether it is the last thread in the queue.
This function returns true
if the thread was unparked by a call to
unpark_one
or unpark_all
, and false
if the validation function failed
or the timeout was reached.
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
or unpark_requeue
, but it is not
allowed to call park
or panic.