| |||||||||
In software engineering, a spinlock is a lock where the thread simply waits in a loop ("spins") repeatedly checking until the lock becomes available. This is also known as "busy waiting" because the thread remains active but isn't performing a useful task. Once acquired, spinlocks will be held until they are released or the thread blocks (aka "goes to sleep").
Spinlocks are very efficient if threads are only likely to be blocked for a short period of time, as they avoid the overhead of operating system process re-scheduling. For this reason, spinlocks are often used within operating system kernels in circumstances where they are likely to be efficient. They are wasteful if the lock is held for a long period of time because they are not voluntarily allowing other threads to run.