A spinlock is a simple, fairly primitive type of thread mutex. The core premise is based on atomic test-and-set operations: one thread sets the flag, the other thread continues to spin (using CPU cycles) until the lock becomes available.

Spinlocks don’t really work without a pre-emptive scheduler, because the other threads may never relinquish control. Spinlocks are also extremely wasteful by premise, which gets worse with multiple threads (on a single CPU machine), because each thread will spin for the duration of a time slice before giving up the CPU, which wastes valuable cycles. If we have threads and CPU cores, this is fine.

Note that it’s also possible in this case for threads to starve in this case without a schedule or priority mechanism. For example, one thread could be continually waiting, while other threads keep