If the spinlock is not locked, lock it and return; if is is locked, wait until it is unlocked, then lock it and return. Uses atomic compare and swap operations that are safe across processors and safe for out of order operations, and which are more efficient than operating system locks. Use spinlocks to protect access to shared data, especially in functions that do little more than read or write such data, for example: