Glossary
lck_mtx (kernel mutex)
XNU's default kernel-side mutex. Block-and-wait under contention, adaptive-spin on short waits, priority-inheriting to prevent inversion.
lck_mtx_t is XNU's general-purpose kernel mutex. The workhorse synchronization primitive — most kernel data structures (proc table, vnodes, IOKit objects, file descriptors) are protected by an lck_mtx.
Properties:
- Block-and-wait under contention. Waiting threads sleep; the OS can use the CPU for other work.
- Adaptive spinning: a short spin attempt before sleeping, on the bet that the holder will release soon and a context switch can be avoided.
- Priority inheritance: a low-priority thread holding a mutex contended by a high-priority one is temporarily boosted to the higher priority. Prevents the classic priority inversion.
- Lock-class group required: every
lck_mtxbelongs to a lock group for telemetry and deadlock detection.
lck_mtx_lock(&my_lock);
// critical section — may sleep, may take other locks
lck_mtx_unlock(&my_lock);
Default to lck_mtx for everything that doesn't have a specific reason to use a different primitive.
See also: lck_spin, the kernel synchronization article.