GATE CSE
First time here? Checkout the FAQ!
x
+2 votes
66 views
What is SPIN-LOCK..?
asked in Databases by (75 points)   | 66 views

1 Answer

+3 votes
Best answer

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.

answered by Boss (6k points)  
selected by
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.



Top Users Sep 2017
  1. Habibkhan

    7096 Points

  2. Warrior

    2574 Points

  3. Arjun

    2412 Points

  4. rishu_darkshadow

    2402 Points

  5. A_i_$_h

    2204 Points

  6. nikunj

    1980 Points

  7. manu00x

    1846 Points

  8. makhdoom ghaya

    1760 Points

  9. Bikram

    1744 Points

  10. SiddharthMahapatra

    1718 Points


26,115 questions
33,691 answers
79,845 comments
31,098 users