The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
+2 votes
What is SPIN-LOCK..?
asked in Databases by (149 points) | 100 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 */
/* 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 Veteran (11.2k 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.

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.

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

28,944 questions
36,792 answers
34,688 users