2. What are Deadlocks ?
• A set of blocked processes each holding a resource and
waiting to acquire a resource held by another process
in the set .
• In simple words, Deadlock occurs when a process
request the resources , the resources are not available at
that time so the process enter into waiting state . The
requesting resources are held by another waiting process
, both are in waiting state, this situation is called
Deadlock.
3. System Model
Request.
The process requests the resource.
Use.
The process can operate on the resource.
Release.
The process releases the resource.
4. Examples :
System has two disk drives .
P1 and P2 each hold one disk drive and each
needs another one.
Two trains approaches each other at crossing,
both will come to full stop each other and neither
shall start until other has gone.
5. Conditions for Deadlock :
Mutual Exclusion :
Processes claim the exclusive control of the resources they
require .
Hold and Wait :
Processes hold resources already allocated to them while
waiting for additional resources.
No preemption :
Resources cannot be removed from the process holding
them until the resources are used to completion.
Circular Wait :
A circular chain of processes exists such that each process
hold one or more resources that are being requested by
next process in the chain.
6. Traffic Example :
• Traffic only in one direction.
• Each section of the bridge can be viewed as a resource.
• Deadlock is occurred and it can be resolves if one car
backs up ( preempt resources and rollback).
8. Methods of Handling
Deadlocks
• We can use a protocol to prevent or avoid deadlocks,
ensuring that the system will never enter a deadlocked state.
• We can allow the system to enter a deadlocked state, detect
it, and recover.
• We can ignore the problem altogether and pretend that
deadlocks never occur in the system.
9. Deadlock Prevention
Prevention Eliminates one of the Four
Conditions
• Elimination of Mutual Exclusion
• Elimination of Hold&Wait condition
• Elimination of No preemption condition
• Elimination of Circular Wait Condition
10. Deadlock Avoidance
Dead lock avoidance technique is used
to avoid deadlock.
Safe State: if deadlock not occur then it is safe state.
Unsafe State: if deadlock occur then it is unsafe
state. The idea of avoiding deadlock is simply not allow
the system to enter an unsafe state.
12. Banker’s Algorithm
Multiple instances
Each process must have a priority claim for
maximum use.
When a process requests a resource it may have
to wait.
When a process gets all its resources it must
return them in a finite amount of time.
13. Recovery from Deadlocks
• Process Termination
Abort all the process until the deadlock cycle is
eliminated.
• Resource Preemption
Preempt resources by selecting a victim and roll
it back by using starvation.