Académique Documents
Professionnel Documents
Culture Documents
Starvation
CHAPTER 6
Objectives
2
Objectives
3
Topics
4
Principles of Deadlock
Resource Categories
Deadlock Strategies
Deadlock Prevention
Deadlock Avoidance
Deadlock Detection
Principle of Deadlock
The permanent blocking of a set of processes that
Illustration of Deadlock
I need
quad C and
B
I need
quad B and
C
I need
quad A and
B
I need
quad D and
A
Potential Deadlock
Illustration of Deadlock
HALT
until D is
free
HALT
until C is
free
HALT
until B is
free
HALT
until A is
free
Actual Deadlock
Resource Categories
Reusable Resources
Can be used by one process at a
Consumable
Resources
Created (produced) and
destroyed (consumed) by a
process
May take a rare combination of
events to cause deadlock
E.g. - Interrupts, signals,
messages, and information in I/O
buffers
P0
P1
Q0
Q1
P2
Q2
Request 80Kb
Request 60 Kb
P2
Request 70Kb
Request 80 Kb
second request
P1
Receive(P2);
...
Send(P2, M1);
...
P2
Receive(P1);
...
Send(P1, M2);
Circular Wait
resource
Prevent Deadlock
adopt a policy that eliminates one of the conditions
Avoid Deadlock
make the appropriate dynamic choices based on the
current state of resource allocation
Detect Deadlock
attempt to detect the presence of deadlock and take
action to recover
Deadlock Prevention
Indirect method
prevent the occurrence of one of the three
necessary conditions
2. Direct method
to prevent the occurrence of circular wait.
Deadlock Avoidance
A decision is made dynamically whether the
types of resources.
Definition of the vectors and matrices:
Resource Vector= R = (R1, R2,, Rm)
Total amount of each resource in the system
Available Vector = V = (V1, V2,, Vm)
Total amount of each resource not allocated to any
process.
Claim Matrix =C =
..
.
..
.
Allocation Matrix =A =
..
.
..
.
of resources to processes
Example 1
Figure 6.7a shows the state of a system consisting
Example 1
R1
R2
R3
R1
R2
R3
P1
P2
P3
R1
R2
R3
P4
R1
R2
R3
P1
P2
P3
P4
Claim Matrix
Allocation
Matrix
Initial State
Resource Vector
Available Vector
Example 1
Steps needed to check either it is a safe state or
not:
1. Construct the Need Matrix
Need Matrix = Claim Matrix Allocation Matrix
R1
R2
R3
P1
P2
P3
P4
Example 1
2. To check either the current state is save or not safe,
o Compare the content of available vector with the
need matrix.
o
Example 1
3. After a process runs to completion, it will release all
the resources to system. Construct new available
vector.
o New AV = Current Av + Allocation Matrix of the
chosen process
= 011+ 612
= 623
Example 1
R1
R2
R3
P1
P2
P3
P4
R1
R2
R3
P1
P2
P3
P4
Claim Matrix
Allocation
Matrix
P2 Runs to Completion
R1
R2
R3
Available Vector
Example 1
R1
R2
R3
P1
P2
P3
P4
R1
R2
R3
P1
P2
P3
P4
Claim Matrix
R1
R2
R3
Available Vector
Allocation
Matrix
P1 Runs to Completion
Example 1
R1
R2
R3
P1
P2
P3
P4
R1
R2
R3
P1
P2
P3
P4
Claim Matrix
R1
R2
R3
Available Vector
Allocation
Matrix
P3 Runs to Completion
Example 1
R1
R2
R3
P1
P2
P3
P4
R1
R2
R3
P1
P2
P3
P4
Claim Matrix
R1
R2
R3
Available Vector
Allocation
Matrix
P4 Runs to Completion
When all processes run to completion, the value for
Example 2
Figure 6.8a shows the state of a system consisting
Example 2
R1
R2
R3
R1
R2
R3
P1
P2
P3
R1
R2
R3
P4
R1
R2
R3
P1
P2
P3
P4
Claim Matrix
Allocation
Matrix
Initial State
Resource Vector
Available Vector
Example 2
R1
R2
R3
P1
P2
P3
P4
R1
R2
R3
P1
P2
P3
P4
Claim Matrix
R1
R2
R3
Available Vector
Allocation
Matrix
Deadlock Detection
Does not limit resource access or restrict process
actions.
Resource access are granted to process whenever
possible.
OS will periodically performs
an algorithm to check if deadlock present
an algorithm to recover from deadlock
Deadlock Detection
The deadlock check can be performed at every
resource request.
Checking at each resource request has two
advantages:
i.
ii.
time.
used.
Request matrix Q is define such that Qij represent
the amount of resources of type j requested by
process i.
Example
Example
The algorithm proceeds as follows:
1.
Mark P4, because P4 has no allocated resources.
2.
Set W = ( 0 0 0 0 1 )
3.
The request of P3 is less than equal to W, so mark P3
and set W = W + ( 0 0 0 1 0)
=(00011)
4.
No other unmarked process has a row in Q is less than
or equal to W. Terminate the algorithm.
The algorithm concludes with P1 and P2
following way:
Group resources into a number of different resource
classes
Use the linear ordering strategy (prevention of circular
wait) to prevent deadlock between resource classes
Within a resource class, use the algorithm that is most
appropriate for that class.