Main index | Section 9 | Options |
See mutex(9) for details.
See mtx_pool(9) for details.
Reader/writer locks can be treated as mutexes (see above and mutex(9)) with shared/exclusive semantics. Reader/writer locks support priority propagation like mutexes, but priority is propagated only to an exclusive holder. This limitation comes from the fact that shared owners are anonymous.
See rwlock(9) for details.
See rmlock(9) for details.
See sx(9) for details.
See lock(9) for details.
See sema(9) for details.
See condvar(9) for details.
The parameter chan is an arbitrary address that uniquely identifies the event on which the thread is being put to sleep. All threads sleeping on a single chan are woken up later by wakeup() (often called from inside an interrupt routine) to indicate that the event the thread was blocking on has occurred.
Several of the sleep functions including msleep(), msleep_spin(), and the locking primitive sleep routines specify an additional lock parameter. The lock will be released before sleeping and reacquired before the sleep routine returns. If priority includes the PDROP flag, then 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 Giant mutex (even if recursed) while the thread is suspended and will reacquire the Giant mutex (restoring any recursion) before the function returns.
The pause() function is a special sleep function that waits for a specified amount of time to pass before the thread resumes execution. This sleep cannot be terminated early by either an explicit wakeup() or a signal.
See sleep(9) for details.
The following primitives perform bounded sleeps: mutexes, reader/writer locks and read-mostly locks.
The following primitives perform unbounded sleeps: sleepable read-mostly locks, shared/exclusive locks, lockmanager locks, counting semaphores, condition variables, and sleep/wakeup.
Note that the lock passed to one of the sleep() or cv_wait() functions is dropped before the thread enters the unbounded sleep and does not violate this rule.
You want: | spin mtx | mutex/rw | rmlock | sleep rm | sx/lk | sleep |
You have: | -------- | -------- | ------ | -------- | ------ | ------ |
spin mtx | amp;ok | amp;no | amp;no | amp;no | amp;no | amp;no-1 |
mutex/rw | amp;ok | amp;ok | amp;ok | amp;no | amp;no | amp;no-1 |
rmlock | amp;ok | amp;ok | amp;ok | amp;no | amp;no | amp;no-1 |
sleep rm | amp;ok | amp;ok | amp;ok | amp;ok-2 | amp;ok-2 | amp;ok-2/3 |
sx | amp;ok | amp;ok | amp;ok | amp;ok | amp;ok | amp;ok-3 |
lockmgr | amp;ok | amp;ok | amp;ok | amp;ok | amp;ok | amp;ok |
*1 There are calls that atomically release this primitive when going to sleep and reacquire it on wakeup ( mtx_sleep(), rw_sleep(), msleep_spin(), etc. ).
*2 These cases are only allowed while holding a write lock on a sleepable read-mostly lock.
*3 Though one can sleep while holding this lock, one can also use a sleep() function to atomically release this primitive when going to sleep and reacquire it on wakeup.
Note that non-blocking try operations on locks are always permitted.
Context: | spin mtx | mutex/rw | rmlock | sleep rm | sx/lk | sleep |
interrupt filter: | amp;ok | amp;no | amp;no | amp;no | amp;no | amp;no |
interrupt thread: | amp;ok | amp;ok | amp;ok | amp;no | amp;no | amp;no |
callout: | amp;ok | amp;ok | amp;ok | amp;no | amp;no | amp;no |
direct callout: | amp;ok | amp;no | amp;no | amp;no | amp;no | amp;no |
system call: | amp;ok | amp;ok | amp;ok | amp;ok | amp;ok | amp;ok |
LOCKING (9) | March 29, 2022 |
Main index | Section 9 | Options |
Please direct any comments about this manual page service to Ben Bullock. Privacy policy.
“ | Today, the Unix equivalent of a power drill would have 20 dials and switches, come with a nonstandard plug, require the user to hand-wind the motor coil, and not accept 3/8" or 7/8" drill bits (though this would be documented in the BUGS section of its instruction manual). | ” |
— The Unix Haters' handbook |