a spinlock
A spinlock is the simplest real lock: a mutex whose waiting strategy is busy waiting. A thread that finds the lock taken does not go to sleep; it spins in a tight loop, repeatedly trying to grab the lock until it succeeds. The name says it all — while you wait, your thread spins. It is the direct, practical embodiment of a test-and-set or compare-and-swap loop wrapped up as a reusable lock.
Its appeal is speed when contention is brief. Because the waiter never sleeps, there is no cost of a context switch into the kernel to block and another to wake up; the moment the holder releases the lock, the spinning thread grabs it almost instantly. That makes spinlocks ideal for protecting very short critical sections on multiprocessor machines, where the holder is genuinely running on another core and will release the lock in a few instructions. This is exactly the regime inside an operating-system kernel, where many data structures are guarded by spinlocks held for only a handful of instructions.
The flip side is that a spinlock is only appropriate under specific conditions, and misused it is wasteful or disastrous. If the critical section is long, every waiter burns a whole CPU core doing nothing for the duration — pure waste. On a uniprocessor it is almost always wrong: the spinning waiter prevents the holder from being scheduled to release the lock. And classic spinlocks usually do not guarantee bounded waiting, so under heavy contention one thread can be repeatedly beaten to the lock. There is also a critical kernel rule: a thread must never sleep or be preempted while holding a spinlock, because anyone spinning for it would then waste enormous time; kernels often disable preemption (and sometimes interrupts) for the brief life of a spinlock. The decision spinlock-versus-blocking-lock comes down to: will the wait be shorter than the cost of sleeping?
A kernel updates a shared list whose modification takes ~20 instructions. It uses a spinlock: a waiting CPU spins for those few nanoseconds rather than paying the much larger cost of sleeping and being woken. If the same list took milliseconds to update, a blocking lock would be the right choice instead.
Spinlock = mutex + busy-wait. Great for short waits on multicore; wrong for long waits or uniprocessors.
Never sleep or do slow work while holding a spinlock — every waiter is burning a core meanwhile. On a single CPU a spinlock waiting for a not-yet-running holder can hang the system.