66 views
What is SPIN-LOCK..?

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
Is it same as busy wait?
Yes, spin lock is same as Busy wait.

There is another kind of waiting which is known as Live Lock - where 2 or more process keep executing and wasting CPU cycle . But no one can enter into CS .

Livelock is a kind of deadlock.
@Sir

Busy wait/ Spin lock is when one process is in CS and other is checking condition again and again to get into CS. So other process is wasting cpu.

But how can it be a deadlock/livestock?

In Livelock no process can enter into CS.

livelock is similar to a deadlock, except that the states of the processes involved in the livelock constantly change with regard to one another, none progressing ..

For your actual question - spinlock is same as busy waiting when one process enter into CS and other keep waiting.

In case of Livelock none of them can able to enter.