When a process is continuously checking for the condition to acquire a lock or permission to enter into critical section then it is called spin lock, the CPU cycles consumed in spin lock by the process goes waste because that process is not doing any important task at that interval while it is continuously checking for acquiring the lock.
Suppose, take this example:-
/* P1 */
while (true) {
wants1 = true;
while (wants2 == true);
/* Critical Section */
wants1 = false;
}
/* Remainder section */
|
/* P2 */
while (true) {
wants2 = true;
while (wants1 == true);
/* Critical Section */
wants2=false;
}
/* Remainder section */
|
In this, if P1 is in critical section, and P2 wants to enter in critical section then it will continuously checking for the condition in the while loop to become false so that it gets a chance to enter into critical section, but in this interval P2 is not doing any productive work it simply checking the condition which is not productive and wasting CPU cycle. So, we can say here P2 is in Spin lock.