
1
Deadlock
COMP755 Advanced Operating
Systems
Deadlock Definitions
• A deadlock occurs when two or more
tasks are waiting for each other and they
cannot proceed.
• Deadlock is a situation where two or more
processes are each waiting for a resource
that another process in the group holds.
• Deadlock is the permanent blocking of a
set of processes.
• Deadlock occurs when waiting processes
cannot be removed from the wait state.
Hung Systems
• Deadlock typically results in “hung”
systems. The program is running, but
nothing is happening.
• If there is a possible order of execution
that will allow all tasks to complete, then
the system is not deadlocked.
Deadlock Example
• Consider a program with two threads.
Each thread requires exclusive access to
the resources A and B.
Thread 1
Acquire resource A
Acquire resource B
Thread 2
Acquire resource B
Acquire resource A
Both threads are deadlocked.
Necessary Conditions for Deadlock
1. Mutual Exclusion
2. No Preemption
3. Hold and Wait
4. Circular wait
Mutual Exclusion
• Deadlock will only occur if a resource
cannot be simultaneously used by more
than one task.
• Some resources can easily be shared
– Read only files
– Code with no shared data