Title: Problems associated with Deadlock Prevention
1Problems associated with Deadlock Prevention
- Deadlock prevention , attempts to prevent at
least one of the three necessary conditions. - This may lead to inefficient use of resources as
well as inefficient execution of processes.
2Deadlock Avoidance
- Basis There exists a priori knowledge about the
following - a) The Total Amount of resources at hand
hence applicable to reusable resources only. - b) For any process , its maximum demand for
all types of resources . - Basic Approaches
- Do not start a process if its demands might
lead to a deadlock. - Do not grant incremental resource request to a
process if this allocation might lead to a
deadlock.
3Deadlock Avoidance Principle - 1
- Data Structures used
- N processes P N P1,,Pi,.Pn
- M resources R M R1,..,Rj, , Rm
Where Rj No. of Instances of the jth
resource. Each of the N processes has got a
maximum demand for instances of each of the M
existing resources
4Deadlock Avoidance Principle - 2
- Data Structures used Contd.
- Claim Matrix C N,M C11,,C1j,.C1m
-
Ci1,,Cij,., Cim -
Cn1,,Cnj,.,Cnm
Here C ij ? Max. Requirement of Process Pi for
the instances of the jth resource.
5Deadlock Avoidance Principle - 3
- Data Structures used Contd.
- Allocation Matrix A N,M A11,,A1j,.A1m
-
Ai1,,Aij,., Aim -
An1,,Anj,.,Anm
Here Aij ? Number of Instances of the jth
Resource currently allocated to the Process Pi .
6Deadlock Avoidance Principle - 4
- Data Structures used Contd.
- Available Matrix V M V1,..,Vj, , Vm
Where Vj No. of Instances of the jth resource
left / existing after allocating some as
specified by the allocation matrix A N,M.
Hence Rj Vj ? A kj ( for k 1 .. N )
7Deadlock Avoidance Principle - 5
- For all Resources Rj Vj ? A ki ( for j 1
.. N ) - i.e. all resources are either allocated
or available. - 2. Ckj lt Rj for all k, j i.e. No processes
can claim for more instances of the jth resource
than that exists. - 3. Akj lt Ckj , for all k, j i.e. No processes
is allocated more instances of the jth resource
than its max. claim.
8Deadlock Avoidance Policy 1
- Process Initiation Denial No new process is
started if its resource requirements might lead
to a deadlock. - Start a new process P (n1) only if the maximum
claim of all current processes plus that of the
new process can be met. - Rj gt C (n1)j ? C ki ( for k 1 .. N )
9Deadlock Avoidance Policy 2
- Resource Allocation Denial
- Bankers Algorithm Allocate resources to
processes so that one always arrives at a safe
state The current state of the system is
described by the two vectors Resource RN
Available VN as well as the two matrices Claim
CM,N Allocation AM,N . - A safe state is one in which there exists at
least one sequence of allocation of resource
instances to processes that does not result in
deadlock. Refer to worked out example .
10Bankers Algorithm - 1
- struct State
-
- int Resource M // The Resource Vector
- int Available M // The Available Vector
- int Claim N M // The Claim Matrix
- int Allocation N M // The Allocation
Matrix -
11Resource Allocation Algorithm
- if ( Allocation I, Request ) gt
Claim I, ) - / Total Request gt Claim /
- lt Flash Error gt
- else if ( Request gt Available )
- lt Suspend Process gt
- else / Simulate Allocation /
-
- lt Define New-state by
- Allocation I, ? Allocation I,
Request - Available ? Available -
Request gt -
- if ( Safe (New-state))
- lt Carry Out Allocation gt
- else
-
- lt Restore Original State gt
- lt Suspend Process gt
-
12Test for Safety / Bankers Algorithm
- boolean Safe (State S)
-
- int Current_Avail M
- WAIT_LIST lt Number of Processes gt
- Current_Avail M ? Available M
- WAITI_LIST ? All Processes
- Possible ? TRUE
- while (Possible)
- // begin while 1
- ltFind a Process Pk in WAIT_LIST such
that - Current_Avail gt Claim K, -
Allocation K, gt - if (found)
// Simulate
Execution of Pk -
- Current_Avail ? Current_Avail
Allocation K, - WAIT_LIST ? WAIT_LIST Pk
-
- else
- Possible ? FALSE
- // end while
13Deadlock Avoidance Basic Features
- It allows the three necessary conditions for
deadlock but makes judicious choices to assure
that the deadlock point is never reached. - It allows more concurrency than prevention.
- With deadlock avoidance, a decision is made
dynamically whether the current resource
allocation request will, if granted, potentially
lead to a deadlock. - NOT applicable to consumable resources.