Deadlock in Operating System (OS)
Deadlock Introduction in Operating System
Important Features of Deadlock –
Deadlock refers to the condition when 2 or more processes are waiting for each other to release a resource indefinitely. A process in nature requests a resource first and uses it and finally releases it.
But in deadlock situation, both the processes wait for the other process . Let’s look at one example to understand it – Say, Process A has resource R1 , Process B has resource R2. If Process A request resource R2 and Process B requests resource R1, at the same time , then deadlock occurs.
- In deadlock, processes get blocked because each process is holding some resource and they are waiting for other resource , which is held by another process.
- Deadlock usually occurs in multiprocessing, time- sharing etc
- In Multiprocessing, many processes share a specific type of mutually exclusion resource known as soft lock.
- Time Sharing computers are equipped with a hardwired lock which gaurantees exclusive access to processes , thus preventing deadlock.
- There is no general solution to avoid soft deadlock.
Conditions for Deadlock
Deadlock can occur if all the given 4 conditions ( Coffman Conditions ) are satisfied, that is if all are true :
- Mutual Exclusion
- Hold and Wait
- No Preemption
- Circular wait
Let’s look at each one in detail :
- Mutual exclusion – If At least one or more resource are in non shareable mode , the resources should be in mutual exclusion. Non Shareable means , resource can’t be used by more than 1 process at a time, unless the resource gets released.
- Hold and Wait – Processes which are already holding at least 1 resource may request new resource.
- No Pre emptive condition – Resources can’t be released by force , only the process holding the resource can release it, which does so after the process has finished its task.
- Circular wait – 2 or more process form a circular chain where each process waits and want to acquire the resource which the next process in the chain holds.