Skip to content

Glossary

lck_spin (kernel spinlock)

Busy-wait kernel lock for very short critical sections in interrupt or scheduler context where blocking isn't an option.

lck_spin_t is XNU's busy-wait spinlock. A thread that can't acquire spins on an atomic flag until it can claim the lock. Used where blocking isn't an option — interrupt handlers, scheduler internals, anywhere lck_mtx would be too expensive or incorrect.

Constraints:

  • The critical section must be very short (dozens of instructions, not hundreds).
  • The holder must not block, sleep, or take any lock that might block.
  • Under contention, the spinner is burning CPU on a thread that could otherwise be doing work.
apple-oss-distributions/xnuosfmk/kern/locks.cSpinlock implementation — alongside mutexes and rwlocks.View on GitHub(line )
lck_spin_lock(&proc_list_spin);
// very short critical section, no sleep
lck_spin_unlock(&proc_list_spin);

There's an IRQ-safe variant (lck_spin_lock_grp_irq_set) that disables interrupts while held — required when the same lock is taken from both thread context and interrupt context.

Default to lck_mtx. Reach for lck_spin only when you can't sleep.

See also: lck_mtx, AST, the kernel synchronization article.