handle event-based thread blocking.
If a thread must wait for an
external event, it is put to sleep by
Threads may also wait using one of the locking primitive sleep routines
is an arbitrary address that uniquely identifies the event on which
the thread is being put to sleep.
All threads sleeping on a single
are woken up later by
often called from inside an interrupt routine, to indicate that the
resource the thread was blocking on is available now.
specifies a new priority for the thread as well as some optional flags.
If the new priority is not 0,
then the thread will be made
runnable with the specified
when it resumes.
should never be used, as it is for compatibility only.
A new priority of 0 means to use the threads current priority when
it is made runnable again.
flag, pending signals are allowed to interrupt the sleep, otherwise
pending signals are ignored during the sleep.
is set and a signal becomes pending,
is returned if the current system call should be restarted if
is returned if the system call should be interrupted by the signal
flag is specified in addition to
then the sleeping thread is not stopped when
or some other stop action occurs while it is sleeping.
Instead, it is woken up, with the assumption
that the stop will occur on reaching a stop
point when returning to usermode.
The flag should be used when the sleeping thread owns resources, for instance
vnode locks, that should be released in a timely fashion.
is a string describing the sleep condition for tools like
Due to the limited space of those programs to display arbitrary strings,
this message should not be longer than 6 characters.
specifies a timeout for the sleep.
is not 0,
then the thread will sleep for at most
timo / hz
If the timeout expires,
then the sleep function will return
parameter instead of
It allows the caller to specify relative or absolute wakeup time with higher resolution
in form of
.Vt sbintime_t .
allows the caller to specify wanted absolute event precision.
allows the caller to pass additional
Several of the sleep functions including
and the locking primitive sleep routines specify an additional lock
The lock will be released before sleeping and reacquired
before the sleep routine returns.
the lock will not be reacquired before returning.
The lock is used to ensure that a condition can be checked atomically,
and that the current thread can be suspended without missing a
change to the condition, or an associated wakeup.
In addition, all of the sleep routines will fully drop the
(even if recursed)
while the thread is suspended and will reacquire the
mutex before the function returns.
Note that the
mutex may be specified as the lock to drop.
In that case, however, the
flag is not allowed.
To avoid lost wakeups,
either a lock should be used to protect against races,
or a timeout should be specified to place an upper bound on the delay due
to a lost wakeup.
As a result,
function should only be invoked with a timeout of 0 when the
mutex is held.
function requires that
reference a default, i.e. non-spin, mutex.
Its use is deprecated in favor of
which provides identical behavior.
function requires that
reference a spin mutex.
function does not accept a
parameter and thus does not support changing the current threads priority,
or catching signals via the
function is a wrapper around
that suspends execution of the current thread for the indicated timeout.
The thread can not be awakened early by signals or calls to
function makes the first thread in the queue that is sleeping on the
This reduces the load when a large number of threads are sleeping on
the same address, but only one of them can actually do any useful work
when made runnable.
Due to the way it works, the
function requires that only related threads sleep on a specific
It is the programmers responsibility to choose a unique
function did not require this, though it was never good practice
for threads to share a
When converting from
pay particular attention to ensure that no other threads wait on the