The Gateway to Computer Science Excellence
+4 votes
in Operating System by Junior (593 points) | 2.1k views

1 Answer

+8 votes
Best answer

I think everything is different between deadlock and spinlock

Dead Lock: In concurrent computing, a deadlock occurs when two competing actions wait for the other to finish, and thus neither ever does. Deadlock is a common problem in multiprocessing systems, parallel computing, and distributed systems, where software and hardware locks are used to handle shared resources and implement process synchronization.

Spinlock: In software engineering, a spinlock is a lock which causes a thread trying to acquire it to simply wait in a loop ("spin") while repeatedly checking if the lock is available. Since the thread remains active but is not performing a useful task, the use of such a lock is a kind of busy waiting. Once acquired, spinlocks will usually be held until they are explicitly released, although in some implementations they may be automatically released if the thread being waited on (that which holds the lock) blocks, or "goes to sleep".

Summary: Deadlock is a problem, in concurrent programming. While Spinlock is a solution for threads, so that two threads can not access the same resource at a time. 

by Boss (35.6k points)
selected by
So, are spin lock and busy waiting the same?
In busy waiting the process which holds the lock will release the lock after complete executing the critical section/shared section and the process which was waiting for lock, will get the lock but in spin lock the process which holds the lock of cs is waiting to completion of the other process( for example p1 has low priority than p2 and p1 is holding the lock as the p1 go for execution of cs then preemption occurs and p2 came and need the cs in this scenario p1 can't run until p2 completes its work and p2 can't continue because lock is hold by p1 (and p2 is continuing checking for availability of lock that's why spin lock not dead lock).

Spinlocks are only useful in places where anticipated waiting time is shorter than a quantum and preemption doesn't make much sense.

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
50,647 questions
56,493 answers
100,786 users