663 views

1 Answer

Best answer
4 votes
4 votes

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.

selected by

Related questions

2 votes
2 votes
1 answer
1
junaid ahmad asked Jan 20, 2018
461 views
States which of the statements are true and please give some reference :S1:Bounded waiting and progress implies no starvationS2:Bounded waiting doesn't imply starvation f...
0 votes
0 votes
1 answer
2
N3314nch41 asked Sep 10, 2023
341 views
How to approach synchronization (specifically semaphore) question, there size are really intimidating and i’m unable to decode the code written? What to do??