Title: Deadlock Prevention
1Deadlock Prevention
- A conservative approach based on Under committing
resources . - Indirect method Prevent one of the three
necessary conditions from happening. - Direct Method Prevent the circular waiting
scenario i.e. breaking the Cycle in the Cyclic
Graph by making it acyclic.
2Deadlock Prevention Indirect Strategy - 1
- Violate Mutual Exclusion Not viable since most
of the peripheral resources like Tape Drives,
CD-WRITERS happen to be intrinsically non
sharable. Hence any process presenty occupying
any of these resources must have exclusive access
to that resource.
3Deadlock Prevention Indirect Strategy 2
- Violate Hold Wait Not easily accomplished.
Following two possible ways can be explored. - A. Any process may be required to request
all of its required resources at one time and
blocking that process unless all its requested
resources can be granted simultaneously. - Problems
- 1) A process may have to wait for long
before getting all its requested resources when
it could have proceeded with some of its
allocated resources. - 2) Some of the resources allocated to the
process may remain unused for long thereby
denying other processes. - 3) Impractical to obtain all resource
requirements a priori. - 4) Not suitable for consumable resources .
-
4Deadlock Prevention Indirect Strategy 2
Contd.
- Violate Hold Wait Second method.
- B. Before making any fresh request for any
resource, a process may be required to release
all the resources it is holding at that moment.
This may stall the process for long.
5Deadlock Prevention Indirect Strategy 2
contd.
- Violate Hold Wait ( Example) Consider the
following scenario for any typical process Pi. - Sl. No . Activity Required
Resource - 1. Copy Data from Tape Tape Drive, Disk
Drive - to Disk .
- 2. Sort the Disk File. Disk
Drive. - 3. Print the Sorted File. Disk
Drive, Printer. -
6Deadlock Prevention Indirect Strategy 2
contd.
- Violate Hold Wait ( Example)
- Policy 1 Allocates all 3 resources i.e. Tape
Drive , Disk Drive as well as Printer to the
concerned process Pi at the start resulting in
underutilization of resources also some other
processes may starve. - Policy 2 As soon as the process requests for
printer , it is forced to release all other
resources it is holding i.e. the Tape Drive as
well as the Disk Drive causing a Halt in the
printing of the sorted disk file. This inevitably
causes starvation.
7Deadlock Prevention Indirect Strategy 3
- Violate No Pre Emption The general policy
- Process Pi which is currently holding some
resources asks / requests for a new resource
Incremental Request . - Policy A If the resource(s) requested by the
process Pi cannot be granted then preempt / take
away all the resources currently being held by
the process Pi and are marked as free ( Easier
said than done). However the current state of all
the occupied resources needs to be saved. - Restart / Resume the process Pi later when it
can have all its requested resources including
the previously held ones (after restoring the
saved status of resources).
8Deadlock Prevention Indirect Strategy 3
Contd.
- Policy B
- If the resource Rj being requested by the
process Pi cannot be granted then check whether
any of the other processes Pk currently holds
that resource Rj while waiting for some other
resources . - If that is the case then preempt the process
Pk from the resource Rj and allocate that to the
requesting process Pi. However the current state
of that occupied resource Rj w.r.t the process
Pk needs to be saved. - The Preempted process Pk may be restarted
later when it can have all its requested
resources including the previously held ones
(after restoring the saved status of preempted
resources).
9Deadlock Prevention Indirect Strategy 3
Contd.
- Violating Pre Emption Associated problems.
- For most of the resources like tape drive CD
writer , saving current status with possible
resumption later is not at all feasible. - Not applicable for consumable resources.
- Ensuring that the process being preempted
possesses a lower priority than the process being
favored presents an additional overhead.
10Deadlock Prevention Direct Strategy
- Prevent Circular Waiting ? Prevent formation of
Cyclic Resource Allocation Request Graph. - Represents the most effective way of Deadlock
prevention. - Can be done in two ways
- a) By enforcing an ordering on all the
resources and allowing request grant based on
that order. - b) Reduce number of processes thereby
ensuring that some resource instance is always
free (helps to prevent starvation) difficult to
implement.
11Deadlock Prevention Direct Strategy Contd.
- Imposing Resource Ordering Mostly applicable to
reusable resources. - The strategy
- Consider each resource Rj along with all its
instances as a single entity. - Specify a one to one mapping such that
- F Rj ? N where
- 1) N is a natural Number.
- 2) F (Rj) gt F(Ri) i.e. the resource Rj is to be
allocated / used after the resource Ri. -
12Deadlock Prevention Direct Strategy Contd.
- Resource Ordering The policy
- Any request for any instance of any particular
resource Rj by any process Pi , is treated as a
request for F(Rj) ( the mapped natural number ). - Any process Pi can request for a new resource
Rk after holding other resources R0..Rj iff - F (Rk) gt F(Ri) i 0 .. j . Otherwise that
request is not granted i.e. that process Pi is
not allowed to progress. It is also forced to
release ALL the concurrently non sharable
resources currently being held by it.
13Deadlock Prevention Direct Strategy Application
- 1
- Process Dining_Philosopher Pi
- / begin Philosopher /
- repeat / begin repeat /
- Think
- N1ForkI Wait (N1)
- Grab (N1) N2 Fork (I1) 5
- if (N2 ltN1) / Ordering Violation/
- /begin THEN 1/
- print(Illegal Request)
- / Go To Release Fork/
- putdown (N1) Signal (N1)
- /end THEN 1/
14Deadlock Prevention Direct Strategy Application
1(Contd.)
- else / Valid Request /
- / begin ELSE 1 Grab Fork Eat/
- Wait (N2 ) Grab (N2) Eat
- / Release All Forks /
- Putdown ( Fork (I1) 5 )
- Signal ( Fork (I1) 5 )
- Putdown ( Fork I )
- Signal ( Fork I )
- / End ELSE 1/
- forever / end repeat /
- / end philosopher /
15Deadlock Prevention Direct Strategy Application
- 2
- Process Dining_Philosopher Pi
- / begin Philosopher /
- repeat / begin repeat /
- Think if (Pi gt 3)
- /begin THEN 1/
- En_Queue (Room) / Only 3
philosophers are allowed/ - else / begin ELSE 1/
- N1ForkI Wait (N1)
- Grab (N1) N2 Fork (I1) 5
- if (N2 ltN1) / Ordering Violation/
- /begin THEN 2/
- print(Illegal Request)
- / Go To Release Fork/
- putdown (N1) Signal (N1)
- / end THEN 2 /
16Deadlock Prevention Direct Strategy Application
1(Contd.)
- else / Valid Request /
- / begin ELSE 2 Grab Fork Eat/
- Wait (N2 ) Grab (N2) Eat
- / Release All Forks /
- Putdown ( Fork (I1) 5 )
- Signal ( Fork (I1) 5 )
- Putdown ( Fork I )
- Signal ( Fork I )
- / end ELSE 2/
- De_Queue(Room) / Allow one more
Philosopher from Room/ - /end ELSE 1/
- forever / end repeat /
- / end philosopher /