Spinlocks

Spinlocks are one of the simplest and lightweight mutual exclusion mechanisms widely implemented by most concurrent programming environments. A spinlock implementation defines a lock structure and operations that manipulate the lock structure. The lock structure primarily hosts an atomic lock counter among other elements, and operations interfaces include:

  • An initializer routine, that initializes a spinlock instance to the default (unlock) state
  • A lock routine, that attempts to acquire spinlock by altering the state of the lock counter atomically
  • An unlock routine, that releases the spinlock by altering counter into unlock state

When a caller context attempts to acquire spinlock while it is locked (or held by another context), ...

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.