Deadlocks

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

Deadlocks

❑ Introduction to Deadlocks
❑ Deadlock Prevention
Deadlock
• condition wherein a set of processes cannot continue executing
because each process is waiting for a resource that is being held or
used by another process within the set.

Process
P1
P1 is
P1 is currently requesting to
using R1 use R2

Resource Resource
R1 R2

P2 is P2 is currently
requesting to using R2
use R1
Process
P2

Figure 7.1 Example of a Deadlock


Figure 7.2 Traffic Deadlock
Deadlock Avoidance
• In deadlock avoidance, deadlocks may occur but the operating
system will avoid actions that could lead to deadlocks.

Unsafe State
• a state that may lead to a deadlock and must be avoided.

Safe State
• a state that has a scheduling order or a sequence of processes in
which every process in the sequence can complete its execution
• If a system is in safe state → no deadlocks

• If a system is in unsafe state → possibility of deadlock.

• Avoidance → ensure that a system will never enter an unsafe


state.
Assume that there are three processes and ten resources of the same type.
The table below shows the current resource allocation.

• P2 → P3 → P1
• P2 → P1 → P3

Banker’s Algorithm
• used to determine if the current state of the system is safe or not.
• max [ i ] – maximum number of resources that a certain process needs
to complete its execution.

• hold [ i ] – total number of resources that a certain process is currently


holding.

• need [ i ] – total number of resources that a certain process still needs


to complete its execution.

• total – total number of resources the computer system has.

• available – total number of resources that are available for allocation


to the processes. This can be expressed as:

available = total - σ𝑛𝑖=1 hold[i]


A system has 4 processes and 10 resources of the same type.
Assume the following resource allocation table.
• P3 → P2 → P1 → P4

• P3 → P4 → P1 → P2
A system has 4 processes and 10 resources of the same type.
Assume the following resource allocation table.
• P3 → P4 → P2 → P1

• P3 → P2 → P4 → P1

You might also like