4 Deadlock
4 Deadlock
A deadlock is a situation in which a set of processes are blocked because each process
is holding a resource and waiting for another resource acquired by another process.
Deadlock occurs in multi-processing systems where multiple processes share
resources.
Deadlock
Circular wait
Deadlock Avoidance
4. Deadlock Detection
Detection methods:
Banker's Algorithm ensures that the system never enters an unsafe state. It uses:
The Banker's Algorithm is used to avoid deadlocks by ensuring that the system never enters
an unsafe state.
1. Initialize:
o Work = Available (copy of available resources).
o Finish[] = {false} for all processes (indicating none are finished).
o SafeSequence[] (to store the safe execution order).
2. Find a process P[i] such that:
o Finish[i] == false
o Need[i] ≤ Work (for all resource types)
3. If such a process is found:
o Allocate resources temporarily: Work = Work + Allocation[i]
o Mark Finish[i] = true
o Add P[i] to SafeSequence
o Repeat for all processes.
4. If all processes finish (Finish[] = true for all), Safe State exists → Allow resource
request.
5. If no process can execute, the system is in an Unsafe State → Deny request to avoid
deadlock.
Deadlock detection is used when resource allocation is dynamic, and deadlock avoidance is
not enforced.
1. Initialize:
o Work = Available
o Finish[] = {false} for all processes
2. Find a process P[i] such that:
o Finish[i] == false
o Request[i] ≤ Work (for all resource types)
3. If such a process is found:
o Allocate resources temporarily: Work = Work + Allocation[i]
o Mark Finish[i] = true
o Repeat for all processes.
4. If all processes finish (Finish[] = true for all), No Deadlock.
5. If some processes are still Finish[i] == false, these processes are deadlocked.
Differences