Mutex locks

Spinlocks by design are better suited for scenarios where lock is held for short, fixed intervals of time, since busy-waiting for an indefinite duration would have a dire impact on performance of the system. However, there are ample situations where a lock is held for longer, non-deterministic durations; sleeping locks are precisely designed to be engaged for such situations. Kernel mutexes are an implementation of sleeping locks: when a caller task attempts to acquire a mutex that is unavailable (already owned by another context), it is put into sleep and moved out into a wait queue, forcing a context switch allowing the CPU to run other productive tasks. When the mutex becomes available, the task in the wait queue is woken up ...

Get Mastering Linux Kernel Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.