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), ...