SlideShare a Scribd company logo
Chapter 7
Deadlocks
INTROOS Slides - ccsmwt
Copyright© De La Salle University
Professional Schools, Inc.
College of Computer Studies
Introduction
Several processes may compete for a
finite number of resources
If a process requests for a resource but
it is not available at the time, the
process enters into a wait state
If the resource is held by another
process who is also waiting, the
situation is called a deadlock
INTROOS Slides - ccsmwt
Copyright© De La Salle University
Professional Schools, Inc.
College of Computer Studies
System Model
Types of Resources:
1. Memory space
2. CPU cycles
3. Files
4. I/O devices – printers, tape drives,
etc
INTROOS Slides - ccsmwt
Copyright© De La Salle University
Professional Schools, Inc.
College of Computer Studies
System Model
If a process requests for an instance of a
resource type, the allocation of any
instance of the type will satisfy the request
A process must request a resource before
using it.
A process must release the resource after
using it
A process’ number of requests cannot
exceed the total number of resources
available in the system
INTROOS Slides - ccsmwt
Copyright© De La Salle University
Professional Schools, Inc.
College of Computer Studies
Using a resource
A process may utilize a resource only
in the following sequence:
1. Request … wait if not available
2. Use
3. Release
INTROOS Slides - ccsmwt
Copyright© De La Salle University
Professional Schools, Inc.
College of Computer Studies
When do Deadlock occur?
A set of processes is in a deadlock state when
every process in the set is waiting for an event
that can be caused by only another process in
the set.
P1
P2
P3
P2
P3
P1
INTROOS Slides - ccsmwt
Copyright© De La Salle University
Professional Schools, Inc.
College of Computer Studies
Deadlock Characterization
In a deadlock, processes never finish
executing
System resources are tied up
To detect a deadlock, all of the
necessary conditions must hold
simultaneously
INTROOS Slides - ccsmwt
Copyright© De La Salle University
Professional Schools, Inc.
College of Computer Studies
Necessary Conditions
1. Mutual Exclusion – only one process at a
time can use the resource. It can only be
used if the resource has been released.
2. Hold and Wait –There must exist a
process that is holding at least one
resource and is waiting to acquire
additional resources that are currently
being held by other processes.
INTROOS Slides - ccsmwt
Copyright© De La Salle University
Professional Schools, Inc.
College of Computer Studies
Necessary Conditions
3. No Preemption – Resources cannot
be preempted
4. Circular Wait
P0  P1  P2  …  Pn
INTROOS Slides - ccsmwt
Copyright© De La Salle University
Professional Schools, Inc.
College of Computer Studies
Resource Allocation Graph
The graph consists of a set of vertices V
and a set of edges E. V is partitioned into
2 types:
P = {P1, P2, …, Pn}, the set consisting
of all processes in the system;
R = {R1, R2,…,Rm}, the set containing
all resource types in the system
Pi
Rj
.
.
Rj
INTROOS Slides - ccsmwt
Copyright© De La Salle University
Professional Schools, Inc.
College of Computer Studies
Resource Allocation Graph
(RAG)
 A directed edge from process Pi
to resource type Rj is denoted by
PiRj; it signifies that process Pi
requested an instance of
resource type Rj. (Request Edge)
 A directed edge from resource
type Rj to process Pi is denoted
by RjPi; it signifies that Rj has
been allocated to process Pi
(Assignment Edge)
Pi
Pi
Rj
Rj
INTROOS Slides - ccsmwt
Copyright© De La Salle University
Professional Schools, Inc.
College of Computer Studies
Example RAG
Given: Sets P, R, and E
P = {P1, P2, P3}
R = {R1, R2, R3}
E = {P1R1, P2R3, R1 P2, R2 
P2, R2P1, R3  P3}
Resource Instances:
1 R1; 2 R2; 1 R3
INTROOS Slides - ccsmwt
Copyright© De La Salle University
Professional Schools, Inc.
College of Computer Studies
Example RAG
Process States:
 Process P1 is holding an
instance of resource type R2, and is
waiting for an instance resource type R1
 Process P2 is holding an instance of R1
and R2, and is waiting for an instance of
resource type R3
 Process P3 is holding an instance of R3
INTROOS Slides - ccsmwt
Copyright© De La Salle University
Professional Schools, Inc.
College of Computer Studies
Is there a deadlock?
If the graph contains no cycles, then no
process in the system is deadlocked.
If a graph with multiple instances of
resources contains a cycle, then there
may be a deadlock
If there is only 1 instance of each
resource, then a deadlock has occurred
INTROOS Slides - ccsmwt
Copyright© De La Salle University
Professional Schools, Inc.
College of Computer Studies
Methods for Handling Deadlocks
1. Use a protocol to ensure that the system
will never enter a deadlock state
a. Deadlock Prevention
b. Deadlock Avoidance
2. Allow the system to enter a deadlock state
and then recover
a. Deadlock Detection
b. Deadlock Recovery
3. Ignore the problem and pretend that
deadlock never occurred
INTROOS Slides - ccsmwt
Copyright© De La Salle University
Professional Schools, Inc.
College of Computer Studies
Deadlock Prevention
 For a deadlock to occur,
each of the four necessary
condition holds
 By ensuring that at least one
of the necessary conditions
cannot hold, deadlock is
prevented
INTROOS Slides - ccsmwt
Copyright© De La Salle University
Professional Schools, Inc.
College of Computer Studies
Deadlock Prevention
1. Mutual Exclusion
 Make the resources sharable so that it
cannot be involved in a deadlock
 A process never needs to wait for a
sharable resource
 However, some resources are
unsharable
INTROOS Slides - ccsmwt
Copyright© De La Salle University
Professional Schools, Inc.
College of Computer Studies
Deadlock Prevention
2. Hold and Wait
 Ensure that whenever a process requests
a resource, it doesn’t hold any other
resources
Protocol:
1. All resources are requested and must be
allocated before execution begins
2. All resources being held at present are
released before the new request is made
INTROOS Slides - ccsmwt
Copyright© De La Salle University
Professional Schools, Inc.
College of Computer Studies
Deadlock Prevention
3. Preemption
 Resources already allocated can be preempted
 If a process that is holding some resources
request for another that cannot be allocated
immediately, then all resources currently held
are preempted/released
 The preempted resources are added to the
resources it is waiting
 Restart only when it regains its old resources, as
well as the new ones it is requesting
 Some resources cannot be released
INTROOS Slides - ccsmwt
Copyright© De La Salle University
Professional Schools, Inc.
College of Computer Studies
Deadlock Prevention
4. Circular Wait
 Prevent circular wait to happen
 Impose a total ordering of all resource types and
require that each process requests resources in
an increasing order of enumeration
 A process may only request a new resource
provided that the new resource’s value is the
largest value among all currently held resources
INTROOS Slides - ccsmwt
Copyright© De La Salle University
Professional Schools, Inc.
College of Computer Studies
Deadlock Prevention
Example: Circular Wait
F (tape drive) = 1
F (disk drive) = 5
F (printer) = 12
If Process 1 holds the disk drive and requests
for the tape drive, it has to relinquish the disk
drive first. However, if process 1 requests for
the printer, it is allocated to it immediately.
INTROOS Slides - ccsmwt
Copyright© De La Salle University
Professional Schools, Inc.
College of Computer Studies
Deadlock Avoidance
 OS will be given, in advance, additional
information concerning which resources a
process will request and use during its
lifetime
 Using this information, the OS can decide
for each request whether the process
should wait or not
 Avoidance is performed by monitoring the
system and try to avoid an unsafe state
INTROOS Slides - ccsmwt
Copyright© De La Salle University
Professional Schools, Inc.
College of Computer Studies
Safe State
A state is safe if the system can allocate
resources to each process (up to the
maximum) in some order and still avoid
a deadlock
A state is safe only if there exists a safe
sequence
INTROOS Slides - ccsmwt
Copyright© De La Salle University
Professional Schools, Inc.
College of Computer Studies
Safe State
A sequence of processes <P1
.. Pn
> is a
safe sequence if for each Pi
, the
resources that Pi
can still request can
be satisfied by the currently available
resources plus the resources held by all
the Pj
, with j<i
INTROOS Slides - ccsmwt
Copyright© De La Salle University
Professional Schools, Inc.
College of Computer Studies
Safe State
If the resources that process Pi
needs
are not immediately available, then Pi
can wait until all Pj
have finished. When
they finished, Pi
can obtain all its
needed resources. When Pi
terminates,
Pi+1
can obtain its needed resources
deadlock state is an unsafe state
not all unsafe states are in deadlock
INTROOS Slides - ccsmwt
Copyright© De La Salle University
Professional Schools, Inc.
College of Computer Studies
Deadlock Avoidance
Example: Given 12 magnetic tape drives
  Process Max
P0 10
P1 4
P2 9
1.) t0:
Process Holds
P0 5
P1 2
P2 2
2.) Suppose that P2 requested and is allocated 1
more tape drive
 
• deadlock avoidance ensures that the system will always
remain in a safe state
INTROOS Slides - ccsmwt
Copyright© De La Salle University
Professional Schools, Inc.
College of Computer Studies
Resource Allocation Graph
For single instances of resource types
a claim edge Pi  Rj indicates that process
Pi may request resource Rj at some time in
the future. (using a dashed line)
When process Pi requests resource Rj, the
claim edge Pi  Rj is converted to a request
edge
When a resource Rj is released by Pi, the
assignment edge Rj  Pi is reconverted to a
claim edge Pi  Rj
INTROOS Slides - ccsmwt
Copyright© De La Salle University
Professional Schools, Inc.
College of Computer Studies
Resource Allocation Graph
Before process Pi starts executing, all its
claim edges must already appear in the RAG
Allow a claim edge Pi  Rj to be added to the
graph only if all the edges associated with
process Pi are claim edges
If Pi requests resource Rj, the request can be
granted only if converting the request edge Pi
 Rj to an assignment edge Rj  Pi does
not result in the formation of a cycle
INTROOS Slides - ccsmwt
Copyright© De La Salle University
Professional Schools, Inc.
College of Computer Studies
Resource Allocation Graph
If no cycle exists, then the allocation of
the resource will leave the system in a
safe state
If a cycle is found, then the
allocation will put the
system in an unsafe
state
INTROOS Slides - ccsmwt
Copyright© De La Salle University
Professional Schools, Inc.
College of Computer Studies
Resource Allocation Graph
R1
R2
P1 P2
INTROOS Slides - ccsmwt
Copyright© De La Salle University
Professional Schools, Inc.
College of Computer Studies
Banker’s Algorithm
applicable to multiple instances of
resource types
when a new process enters the system, it
must declare the maximum number of
instances of each resource type that it may
need
when a user requests, OS must determine if it
will result to an unsafe state
INTROOS Slides - ccsmwt
Copyright© De La Salle University
Professional Schools, Inc.
College of Computer Studies
Data Structures Needed
Let n be the number of processes in the system
and m be the number of resource types
Available - number of available resources of
each type
Max - defines the maximum demand of
each process
Allocation- defines the number of resources of
each type currently allocated to
each process
Need - indicates the remaining resource
need of each process
INTROOS Slides - ccsmwt
Copyright© De La Salle University
Professional Schools, Inc.
College of Computer Studies
Data Structures Needed
Available [j] = k Rj has k instances available
Max [i,j] = k Pi may request at most K instances of Rj
Allocation [i,j] = k Process Pi is currently allocated
k instances of Rj
Need [ i,j] = k Pi may need k more instances of Rj
Need [i,j] = Max[i,j] – Allocation[i,j]
INTROOS Slides - ccsmwt
Copyright© De La Salle University
Professional Schools, Inc.
College of Computer Studies
Notations
Let X & Y be vectors of length n. We
say that X <= Y if and only if X[i] <=
Y[i] for all i = 1,2,3,..n
 We can treat each row in the matrices
Allocation & Need as vectors & refer to them as
Allocationi
& Needi
, respectively
 Allocationi
specifies the resources currently
allocated to Pi
 Needi
specifies the additional resources that
process Pi may still request to complete its task
INTROOS Slides - ccsmwt
Copyright© De La Salle University
Professional Schools, Inc.
College of Computer Studies
Safety Algorithm
1. Let Work & Finish be vectors of length
m & n, respectively. Initialize Work :=
Available & Finish [i] := false, for all
processes Pi
2. Find an i such that
a. Finish [i] = false, and
b. Needi <= Work
if no such i exists, go to step 4
INTROOS Slides - ccsmwt
Copyright© De La Salle University
Professional Schools, Inc.
College of Computer Studies
Safety Algorithm
3. Work := Work + Allocationi
Finish [i] = true
go to step 2
4. If Finish[i] = true for all i, then the
system is in a safe state
INTROOS Slides - ccsmwt
Copyright© De La Salle University
Professional Schools, Inc.
College of Computer Studies
Resource Request Algorithm
Let Requesti be the request vector for process
Pi. If Requesti[j] = k, then Pi wants k instances
of resource type Rj
When a request for resources is made by
process Pi, the ff actions are taken:
1. If Requesti <= Needi, go to step 2.
Otherwise, raise an error condition, since
the process has exceeded its max. claim
INTROOS Slides - ccsmwt
Copyright© De La Salle University
Professional Schools, Inc.
College of Computer Studies
Resource Request Algorithm
2. If Requesti <= Available, go to step 3.
Otherwise, Pi must wait, since the resources
are not available
3. Have the system pretend to have allocated
the requested resources to process Pi by
modifying the state as follows:
Available := Available - Requesti
Allocation := Allocationi + Requesti
Needi := Needi - Requesti
INTROOS Slides - ccsmwt
Copyright© De La Salle University
Professional Schools, Inc.
College of Computer Studies
Resource Request Algorithm
If the resulting resource
allocation state is safe, the
transaction is completed and
process Pi is allocated its
resources. However, if the
new state is unsafe, then Pi
must wait for Requesti and
the old resource-allocation
state is restored.
INTROOS Slides - ccsmwt
Copyright© De La Salle University
Professional Schools, Inc.
College of Computer Studies
Example
PROCESS Allocation Max Available
A B C A B C A B C
P0 0 1 0 7 5 3 3 3 2
P1 2 0 0 3 2 2
P2 3 0 2 9 0 2
P3 2 1 1 2 2 2
P4 0 0 2 4 3 3
Given 5 processes
3 resources A, B, C
A = 10 instances
B = 5 instances
C = 7 instances
1. Request of P1 = (1,0,2)
2. Request of P4 = (3,3,0)
3. Request of P0 = (0,2,0)
INTROOS Slides - ccsmwt
Copyright© De La Salle University
Professional Schools, Inc.
College of Computer Studies
Deadlock Detection
If no deadlock prevention or avoidance
algorithm is available, the system may
have a deadlock situation
System must provide:
 Algorithm that examines the state of the
system to determine whether a deadlock
has occurred
 Algorithm to recover from deadlock
INTROOS Slides - ccsmwt
Copyright© De La Salle University
Professional Schools, Inc.
College of Computer Studies
Single Instance Resource
Type
Wait-for graph – same as RAG but remove
the nodes of type resource & collapse the
appropriate edges
An edge from Pi to Pj in a WFG implies that
process Pi is waiting for process Pj to release
a resource that Pi needs
An edge from Pi  Pj exists in a WFG iff the
corresponding RAG contains 2 edges Pi Rq
& Rq  Pj for some resource Rq
INTROOS Slides - ccsmwt
Copyright© De La Salle University
Professional Schools, Inc.
College of Computer Studies
Example
R3R1
P5
P3
R4
P2P1
P4 R5R2
Note:
Deadlock exists iff
the WFG contains a
cycle
INTROOS Slides - ccsmwt
Copyright© De La Salle University
Professional Schools, Inc.
College of Computer Studies
Several Instances Resource
Type
Data Structures
Available - # of available resource type
Allocation - # of resources of each type
currently allocated to each
process
Request - n X m matrix that indicates
the current request of each
process
INTROOS Slides - ccsmwt
Copyright© De La Salle University
Professional Schools, Inc.
College of Computer Studies
Algorithm
1. Let Work and Finish be vectors of length m
& n, respectively. Initialize Work :=
Available. For i = 1,2,..,n, if Allocationi
≠ 0,
then Finish[i]:= false; otherwise,
Finish[i]:=true
2. Find an index i such that
a. Finish [i] := false, and
b. Requesti
<= Work
If no such i exists, go to step 4
INTROOS Slides - ccsmwt
Copyright© De La Salle University
Professional Schools, Inc.
College of Computer Studies
Algorithm
3. Work := Work + Allocationi
Finish[i] := true
Go to step 2
4. If Finish[i] = false, for some i, 1 <= i <=
n, then the system is in a Deadlock
state. Moreover, if Finish[i] = false,
then process Pi is deadlocked
INTROOS Slides - ccsmwt
Copyright© De La Salle University
Professional Schools, Inc.
College of Computer Studies
Example 1
PROCES
S
Allocation Request Available
A B C A B C A B C
P0 0 1 0 0 0 0 0 0 0
P1 2 0 0 2 0 2
P2 3 0 3 0 0 0
P3 2 1 1 1 0 0
P4 0 0 2 0 0 2
Given 5 processes
3 resource types A,B,C
A = 7 instances
B = 2 instances
C = 6 instances
INTROOS Slides - ccsmwt
Copyright© De La Salle University
Professional Schools, Inc.
College of Computer Studies
Example 2
PROCES
S
Allocation Request Available
A B C A B C A B C
P0 0 1 0 0 0 0 0 0 0
P1 2 0 0 2 0 2
P2 3 0 3 0 0 1
P3 2 1 1 1 0 0
P4 0 0 2 0 0 2
Given 5 processes
3 resource types A,B,C
A = 7 instances
B = 2 instances
C = 6 instances
INTROOS Slides - ccsmwt
Copyright© De La Salle University
Professional Schools, Inc.
College of Computer Studies
Recovery from Deadlock
Options:
1. Abort one or more processes
2. Preempt some resources from one or
more of the deadlocked processes
Process Termination
1. Abort all deadlocked processes
2. Abort one process at a time until the
deadlock cycle is eliminated
INTROOS Slides - ccsmwt
Copyright© De La Salle University
Professional Schools, Inc.
College of Computer Studies
Recovery from Deadlock
Resource Preemption
 Preempt some resources from processes &
given theses resources to other processes until
the deadlock cycle is broken
Issues
1. Selecting a Victim
2. Rollback
3. Starvation

More Related Content

Similar to Deadlocks

Mca ii os u-3 dead lock & io systems
Mca  ii  os u-3 dead lock & io systemsMca  ii  os u-3 dead lock & io systems
Mca ii os u-3 dead lock & io systems
Rai University
 
Deadlocks 160928121516-160928183232
Deadlocks 160928121516-160928183232Deadlocks 160928121516-160928183232
Deadlocks 160928121516-160928183232
marangburu42
 
CH07.pdf
CH07.pdfCH07.pdf
CH07.pdf
ImranKhan880955
 
Module-2Deadlock.ppt
Module-2Deadlock.pptModule-2Deadlock.ppt
Module-2Deadlock.ppt
KAnurag2
 
Gp1242 007 oer ppt
Gp1242 007 oer pptGp1242 007 oer ppt
Gp1242 007 oer ppt
Nivedita Kasturi
 
Mch7 deadlock
Mch7 deadlockMch7 deadlock
Mch7 deadlock
wahab13
 
Operating System Deadlock Galvin
Operating System  Deadlock GalvinOperating System  Deadlock Galvin
Operating System Deadlock Galvin
Sonali Chauhan
 
Deadlock- System model, resource types, deadlock problem, deadlock characteri...
Deadlock- System model, resource types, deadlock problem, deadlock characteri...Deadlock- System model, resource types, deadlock problem, deadlock characteri...
Deadlock- System model, resource types, deadlock problem, deadlock characteri...
Wakil Kumar
 
Process Synchronization And Deadlocks
Process Synchronization And DeadlocksProcess Synchronization And Deadlocks
Process Synchronization And Deadlocks
tech2click
 
Ch 4 deadlock
Ch 4 deadlockCh 4 deadlock
Ch 4 deadlock
madhuributani
 
Deadlock.ppt
Deadlock.pptDeadlock.ppt
Deadlock.ppt
JeelBhanderi4
 
Sucet os module_3_notes
Sucet os module_3_notesSucet os module_3_notes
Sucet os module_3_notes
SRINIVASUNIVERSITYEN
 
Operating System
Operating SystemOperating System
Operating System
Subhasis Dash
 
Deadlock in Operating System
Deadlock in Operating SystemDeadlock in Operating System
Deadlock in Operating System
AUST
 
Galvin-operating System(Ch8)
Galvin-operating System(Ch8)Galvin-operating System(Ch8)
Galvin-operating System(Ch8)
dsuyal1
 
Deadlock
DeadlockDeadlock
Deadlock
Rajandeep Gill
 
Methods for handling deadlock
Methods for handling deadlockMethods for handling deadlock
Methods for handling deadlock
sangrampatil81
 
DeadlockMar21.ppt
DeadlockMar21.pptDeadlockMar21.ppt
DeadlockMar21.ppt
hetrathod001
 
Deadlock (1).ppt
Deadlock (1).pptDeadlock (1).ppt
Deadlock (1).ppt
Nusaike Mufthie
 
OSLec14&15(Deadlocksinopratingsystem).pptx
OSLec14&15(Deadlocksinopratingsystem).pptxOSLec14&15(Deadlocksinopratingsystem).pptx
OSLec14&15(Deadlocksinopratingsystem).pptx
ssusere16bd9
 

Similar to Deadlocks (20)

Mca ii os u-3 dead lock & io systems
Mca  ii  os u-3 dead lock & io systemsMca  ii  os u-3 dead lock & io systems
Mca ii os u-3 dead lock & io systems
 
Deadlocks 160928121516-160928183232
Deadlocks 160928121516-160928183232Deadlocks 160928121516-160928183232
Deadlocks 160928121516-160928183232
 
CH07.pdf
CH07.pdfCH07.pdf
CH07.pdf
 
Module-2Deadlock.ppt
Module-2Deadlock.pptModule-2Deadlock.ppt
Module-2Deadlock.ppt
 
Gp1242 007 oer ppt
Gp1242 007 oer pptGp1242 007 oer ppt
Gp1242 007 oer ppt
 
Mch7 deadlock
Mch7 deadlockMch7 deadlock
Mch7 deadlock
 
Operating System Deadlock Galvin
Operating System  Deadlock GalvinOperating System  Deadlock Galvin
Operating System Deadlock Galvin
 
Deadlock- System model, resource types, deadlock problem, deadlock characteri...
Deadlock- System model, resource types, deadlock problem, deadlock characteri...Deadlock- System model, resource types, deadlock problem, deadlock characteri...
Deadlock- System model, resource types, deadlock problem, deadlock characteri...
 
Process Synchronization And Deadlocks
Process Synchronization And DeadlocksProcess Synchronization And Deadlocks
Process Synchronization And Deadlocks
 
Ch 4 deadlock
Ch 4 deadlockCh 4 deadlock
Ch 4 deadlock
 
Deadlock.ppt
Deadlock.pptDeadlock.ppt
Deadlock.ppt
 
Sucet os module_3_notes
Sucet os module_3_notesSucet os module_3_notes
Sucet os module_3_notes
 
Operating System
Operating SystemOperating System
Operating System
 
Deadlock in Operating System
Deadlock in Operating SystemDeadlock in Operating System
Deadlock in Operating System
 
Galvin-operating System(Ch8)
Galvin-operating System(Ch8)Galvin-operating System(Ch8)
Galvin-operating System(Ch8)
 
Deadlock
DeadlockDeadlock
Deadlock
 
Methods for handling deadlock
Methods for handling deadlockMethods for handling deadlock
Methods for handling deadlock
 
DeadlockMar21.ppt
DeadlockMar21.pptDeadlockMar21.ppt
DeadlockMar21.ppt
 
Deadlock (1).ppt
Deadlock (1).pptDeadlock (1).ppt
Deadlock (1).ppt
 
OSLec14&15(Deadlocksinopratingsystem).pptx
OSLec14&15(Deadlocksinopratingsystem).pptxOSLec14&15(Deadlocksinopratingsystem).pptx
OSLec14&15(Deadlocksinopratingsystem).pptx
 

More from Dwight Sabio

Human Rights Observatory Description
Human Rights Observatory DescriptionHuman Rights Observatory Description
Human Rights Observatory Description
Dwight Sabio
 
RIGHTS-BASED SUSTAINABLE DEVELOPMENT GOALS MONITOR
RIGHTS-BASED SUSTAINABLE DEVELOPMENT GOALS MONITORRIGHTS-BASED SUSTAINABLE DEVELOPMENT GOALS MONITOR
RIGHTS-BASED SUSTAINABLE DEVELOPMENT GOALS MONITOR
Dwight Sabio
 
Report on Girl Children: A Rapid Assessment of their Situation
Report on Girl Children: A Rapid Assessment of their SituationReport on Girl Children: A Rapid Assessment of their Situation
Report on Girl Children: A Rapid Assessment of their Situation
Dwight Sabio
 
Gender ombud report 2016 final
Gender ombud report 2016 finalGender ombud report 2016 final
Gender ombud report 2016 final
Dwight Sabio
 
Strengthening legal referral mechanisms on cases of gender
Strengthening legal referral mechanisms on cases of genderStrengthening legal referral mechanisms on cases of gender
Strengthening legal referral mechanisms on cases of gender
Dwight Sabio
 
IP Report
IP ReportIP Report
IP Report
Dwight Sabio
 
CPU scheduling ppt file
CPU scheduling ppt fileCPU scheduling ppt file
CPU scheduling ppt file
Dwight Sabio
 
Ch3OperSys
Ch3OperSysCh3OperSys
Ch3OperSys
Dwight Sabio
 
OperatingSystemChp3
OperatingSystemChp3OperatingSystemChp3
OperatingSystemChp3
Dwight Sabio
 
ABC Supermarket
ABC SupermarketABC Supermarket
ABC Supermarket
Dwight Sabio
 
Programming Problem 3
Programming Problem 3Programming Problem 3
Programming Problem 3
Dwight Sabio
 
Lab Activity
Lab ActivityLab Activity
Lab Activity
Dwight Sabio
 
Bluetooth
Bluetooth Bluetooth
Bluetooth
Dwight Sabio
 
Programming Problem 2
Programming Problem 2Programming Problem 2
Programming Problem 2
Dwight Sabio
 
Arduino e-book
Arduino e-bookArduino e-book
Arduino e-book
Dwight Sabio
 
Midterm Project Specification
Midterm Project Specification Midterm Project Specification
Midterm Project Specification
Dwight Sabio
 
Game Design Document
Game Design DocumentGame Design Document
Game Design Document
Dwight Sabio
 
Class diagram
Class diagramClass diagram
Class diagram
Dwight Sabio
 
Midterm Project
Midterm Project Midterm Project
Midterm Project
Dwight Sabio
 
ProgrammingProblem
ProgrammingProblemProgrammingProblem
ProgrammingProblem
Dwight Sabio
 

More from Dwight Sabio (20)

Human Rights Observatory Description
Human Rights Observatory DescriptionHuman Rights Observatory Description
Human Rights Observatory Description
 
RIGHTS-BASED SUSTAINABLE DEVELOPMENT GOALS MONITOR
RIGHTS-BASED SUSTAINABLE DEVELOPMENT GOALS MONITORRIGHTS-BASED SUSTAINABLE DEVELOPMENT GOALS MONITOR
RIGHTS-BASED SUSTAINABLE DEVELOPMENT GOALS MONITOR
 
Report on Girl Children: A Rapid Assessment of their Situation
Report on Girl Children: A Rapid Assessment of their SituationReport on Girl Children: A Rapid Assessment of their Situation
Report on Girl Children: A Rapid Assessment of their Situation
 
Gender ombud report 2016 final
Gender ombud report 2016 finalGender ombud report 2016 final
Gender ombud report 2016 final
 
Strengthening legal referral mechanisms on cases of gender
Strengthening legal referral mechanisms on cases of genderStrengthening legal referral mechanisms on cases of gender
Strengthening legal referral mechanisms on cases of gender
 
IP Report
IP ReportIP Report
IP Report
 
CPU scheduling ppt file
CPU scheduling ppt fileCPU scheduling ppt file
CPU scheduling ppt file
 
Ch3OperSys
Ch3OperSysCh3OperSys
Ch3OperSys
 
OperatingSystemChp3
OperatingSystemChp3OperatingSystemChp3
OperatingSystemChp3
 
ABC Supermarket
ABC SupermarketABC Supermarket
ABC Supermarket
 
Programming Problem 3
Programming Problem 3Programming Problem 3
Programming Problem 3
 
Lab Activity
Lab ActivityLab Activity
Lab Activity
 
Bluetooth
Bluetooth Bluetooth
Bluetooth
 
Programming Problem 2
Programming Problem 2Programming Problem 2
Programming Problem 2
 
Arduino e-book
Arduino e-bookArduino e-book
Arduino e-book
 
Midterm Project Specification
Midterm Project Specification Midterm Project Specification
Midterm Project Specification
 
Game Design Document
Game Design DocumentGame Design Document
Game Design Document
 
Class diagram
Class diagramClass diagram
Class diagram
 
Midterm Project
Midterm Project Midterm Project
Midterm Project
 
ProgrammingProblem
ProgrammingProblemProgrammingProblem
ProgrammingProblem
 

Recently uploaded

Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
lorraineandreiamcidl
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Łukasz Chruściel
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
Peter Muessig
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
TheSMSPoint
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
Hornet Dynamics
 
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise EditionWhy Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Envertis Software Solutions
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptxLORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
lorraineandreiamcidl
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
Green Software Development
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
ICS
 
SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024
Hironori Washizaki
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
Green Software Development
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata
 
DDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systemsDDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systems
Gerardo Pardo-Castellote
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Neo4j
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
Philip Schwarz
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
SOCRadar
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate
 

Recently uploaded (20)

Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
 
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise EditionWhy Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptxLORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
 
SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
 
DDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systemsDDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systems
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
 

Deadlocks

  • 2. INTROOS Slides - ccsmwt Copyright© De La Salle University Professional Schools, Inc. College of Computer Studies Introduction Several processes may compete for a finite number of resources If a process requests for a resource but it is not available at the time, the process enters into a wait state If the resource is held by another process who is also waiting, the situation is called a deadlock
  • 3. INTROOS Slides - ccsmwt Copyright© De La Salle University Professional Schools, Inc. College of Computer Studies System Model Types of Resources: 1. Memory space 2. CPU cycles 3. Files 4. I/O devices – printers, tape drives, etc
  • 4. INTROOS Slides - ccsmwt Copyright© De La Salle University Professional Schools, Inc. College of Computer Studies System Model If a process requests for an instance of a resource type, the allocation of any instance of the type will satisfy the request A process must request a resource before using it. A process must release the resource after using it A process’ number of requests cannot exceed the total number of resources available in the system
  • 5. INTROOS Slides - ccsmwt Copyright© De La Salle University Professional Schools, Inc. College of Computer Studies Using a resource A process may utilize a resource only in the following sequence: 1. Request … wait if not available 2. Use 3. Release
  • 6. INTROOS Slides - ccsmwt Copyright© De La Salle University Professional Schools, Inc. College of Computer Studies When do Deadlock occur? A set of processes is in a deadlock state when every process in the set is waiting for an event that can be caused by only another process in the set. P1 P2 P3 P2 P3 P1
  • 7. INTROOS Slides - ccsmwt Copyright© De La Salle University Professional Schools, Inc. College of Computer Studies Deadlock Characterization In a deadlock, processes never finish executing System resources are tied up To detect a deadlock, all of the necessary conditions must hold simultaneously
  • 8. INTROOS Slides - ccsmwt Copyright© De La Salle University Professional Schools, Inc. College of Computer Studies Necessary Conditions 1. Mutual Exclusion – only one process at a time can use the resource. It can only be used if the resource has been released. 2. Hold and Wait –There must exist a process that is holding at least one resource and is waiting to acquire additional resources that are currently being held by other processes.
  • 9. INTROOS Slides - ccsmwt Copyright© De La Salle University Professional Schools, Inc. College of Computer Studies Necessary Conditions 3. No Preemption – Resources cannot be preempted 4. Circular Wait P0  P1  P2  …  Pn
  • 10. INTROOS Slides - ccsmwt Copyright© De La Salle University Professional Schools, Inc. College of Computer Studies Resource Allocation Graph The graph consists of a set of vertices V and a set of edges E. V is partitioned into 2 types: P = {P1, P2, …, Pn}, the set consisting of all processes in the system; R = {R1, R2,…,Rm}, the set containing all resource types in the system Pi Rj . . Rj
  • 11. INTROOS Slides - ccsmwt Copyright© De La Salle University Professional Schools, Inc. College of Computer Studies Resource Allocation Graph (RAG)  A directed edge from process Pi to resource type Rj is denoted by PiRj; it signifies that process Pi requested an instance of resource type Rj. (Request Edge)  A directed edge from resource type Rj to process Pi is denoted by RjPi; it signifies that Rj has been allocated to process Pi (Assignment Edge) Pi Pi Rj Rj
  • 12. INTROOS Slides - ccsmwt Copyright© De La Salle University Professional Schools, Inc. College of Computer Studies Example RAG Given: Sets P, R, and E P = {P1, P2, P3} R = {R1, R2, R3} E = {P1R1, P2R3, R1 P2, R2  P2, R2P1, R3  P3} Resource Instances: 1 R1; 2 R2; 1 R3
  • 13. INTROOS Slides - ccsmwt Copyright© De La Salle University Professional Schools, Inc. College of Computer Studies Example RAG Process States:  Process P1 is holding an instance of resource type R2, and is waiting for an instance resource type R1  Process P2 is holding an instance of R1 and R2, and is waiting for an instance of resource type R3  Process P3 is holding an instance of R3
  • 14. INTROOS Slides - ccsmwt Copyright© De La Salle University Professional Schools, Inc. College of Computer Studies Is there a deadlock? If the graph contains no cycles, then no process in the system is deadlocked. If a graph with multiple instances of resources contains a cycle, then there may be a deadlock If there is only 1 instance of each resource, then a deadlock has occurred
  • 15. INTROOS Slides - ccsmwt Copyright© De La Salle University Professional Schools, Inc. College of Computer Studies Methods for Handling Deadlocks 1. Use a protocol to ensure that the system will never enter a deadlock state a. Deadlock Prevention b. Deadlock Avoidance 2. Allow the system to enter a deadlock state and then recover a. Deadlock Detection b. Deadlock Recovery 3. Ignore the problem and pretend that deadlock never occurred
  • 16. INTROOS Slides - ccsmwt Copyright© De La Salle University Professional Schools, Inc. College of Computer Studies Deadlock Prevention  For a deadlock to occur, each of the four necessary condition holds  By ensuring that at least one of the necessary conditions cannot hold, deadlock is prevented
  • 17. INTROOS Slides - ccsmwt Copyright© De La Salle University Professional Schools, Inc. College of Computer Studies Deadlock Prevention 1. Mutual Exclusion  Make the resources sharable so that it cannot be involved in a deadlock  A process never needs to wait for a sharable resource  However, some resources are unsharable
  • 18. INTROOS Slides - ccsmwt Copyright© De La Salle University Professional Schools, Inc. College of Computer Studies Deadlock Prevention 2. Hold and Wait  Ensure that whenever a process requests a resource, it doesn’t hold any other resources Protocol: 1. All resources are requested and must be allocated before execution begins 2. All resources being held at present are released before the new request is made
  • 19. INTROOS Slides - ccsmwt Copyright© De La Salle University Professional Schools, Inc. College of Computer Studies Deadlock Prevention 3. Preemption  Resources already allocated can be preempted  If a process that is holding some resources request for another that cannot be allocated immediately, then all resources currently held are preempted/released  The preempted resources are added to the resources it is waiting  Restart only when it regains its old resources, as well as the new ones it is requesting  Some resources cannot be released
  • 20. INTROOS Slides - ccsmwt Copyright© De La Salle University Professional Schools, Inc. College of Computer Studies Deadlock Prevention 4. Circular Wait  Prevent circular wait to happen  Impose a total ordering of all resource types and require that each process requests resources in an increasing order of enumeration  A process may only request a new resource provided that the new resource’s value is the largest value among all currently held resources
  • 21. INTROOS Slides - ccsmwt Copyright© De La Salle University Professional Schools, Inc. College of Computer Studies Deadlock Prevention Example: Circular Wait F (tape drive) = 1 F (disk drive) = 5 F (printer) = 12 If Process 1 holds the disk drive and requests for the tape drive, it has to relinquish the disk drive first. However, if process 1 requests for the printer, it is allocated to it immediately.
  • 22. INTROOS Slides - ccsmwt Copyright© De La Salle University Professional Schools, Inc. College of Computer Studies Deadlock Avoidance  OS will be given, in advance, additional information concerning which resources a process will request and use during its lifetime  Using this information, the OS can decide for each request whether the process should wait or not  Avoidance is performed by monitoring the system and try to avoid an unsafe state
  • 23. INTROOS Slides - ccsmwt Copyright© De La Salle University Professional Schools, Inc. College of Computer Studies Safe State A state is safe if the system can allocate resources to each process (up to the maximum) in some order and still avoid a deadlock A state is safe only if there exists a safe sequence
  • 24. INTROOS Slides - ccsmwt Copyright© De La Salle University Professional Schools, Inc. College of Computer Studies Safe State A sequence of processes <P1 .. Pn > is a safe sequence if for each Pi , the resources that Pi can still request can be satisfied by the currently available resources plus the resources held by all the Pj , with j<i
  • 25. INTROOS Slides - ccsmwt Copyright© De La Salle University Professional Schools, Inc. College of Computer Studies Safe State If the resources that process Pi needs are not immediately available, then Pi can wait until all Pj have finished. When they finished, Pi can obtain all its needed resources. When Pi terminates, Pi+1 can obtain its needed resources deadlock state is an unsafe state not all unsafe states are in deadlock
  • 26. INTROOS Slides - ccsmwt Copyright© De La Salle University Professional Schools, Inc. College of Computer Studies Deadlock Avoidance Example: Given 12 magnetic tape drives   Process Max P0 10 P1 4 P2 9 1.) t0: Process Holds P0 5 P1 2 P2 2 2.) Suppose that P2 requested and is allocated 1 more tape drive   • deadlock avoidance ensures that the system will always remain in a safe state
  • 27. INTROOS Slides - ccsmwt Copyright© De La Salle University Professional Schools, Inc. College of Computer Studies Resource Allocation Graph For single instances of resource types a claim edge Pi  Rj indicates that process Pi may request resource Rj at some time in the future. (using a dashed line) When process Pi requests resource Rj, the claim edge Pi  Rj is converted to a request edge When a resource Rj is released by Pi, the assignment edge Rj  Pi is reconverted to a claim edge Pi  Rj
  • 28. INTROOS Slides - ccsmwt Copyright© De La Salle University Professional Schools, Inc. College of Computer Studies Resource Allocation Graph Before process Pi starts executing, all its claim edges must already appear in the RAG Allow a claim edge Pi  Rj to be added to the graph only if all the edges associated with process Pi are claim edges If Pi requests resource Rj, the request can be granted only if converting the request edge Pi  Rj to an assignment edge Rj  Pi does not result in the formation of a cycle
  • 29. INTROOS Slides - ccsmwt Copyright© De La Salle University Professional Schools, Inc. College of Computer Studies Resource Allocation Graph If no cycle exists, then the allocation of the resource will leave the system in a safe state If a cycle is found, then the allocation will put the system in an unsafe state
  • 30. INTROOS Slides - ccsmwt Copyright© De La Salle University Professional Schools, Inc. College of Computer Studies Resource Allocation Graph R1 R2 P1 P2
  • 31. INTROOS Slides - ccsmwt Copyright© De La Salle University Professional Schools, Inc. College of Computer Studies Banker’s Algorithm applicable to multiple instances of resource types when a new process enters the system, it must declare the maximum number of instances of each resource type that it may need when a user requests, OS must determine if it will result to an unsafe state
  • 32. INTROOS Slides - ccsmwt Copyright© De La Salle University Professional Schools, Inc. College of Computer Studies Data Structures Needed Let n be the number of processes in the system and m be the number of resource types Available - number of available resources of each type Max - defines the maximum demand of each process Allocation- defines the number of resources of each type currently allocated to each process Need - indicates the remaining resource need of each process
  • 33. INTROOS Slides - ccsmwt Copyright© De La Salle University Professional Schools, Inc. College of Computer Studies Data Structures Needed Available [j] = k Rj has k instances available Max [i,j] = k Pi may request at most K instances of Rj Allocation [i,j] = k Process Pi is currently allocated k instances of Rj Need [ i,j] = k Pi may need k more instances of Rj Need [i,j] = Max[i,j] – Allocation[i,j]
  • 34. INTROOS Slides - ccsmwt Copyright© De La Salle University Professional Schools, Inc. College of Computer Studies Notations Let X & Y be vectors of length n. We say that X <= Y if and only if X[i] <= Y[i] for all i = 1,2,3,..n  We can treat each row in the matrices Allocation & Need as vectors & refer to them as Allocationi & Needi , respectively  Allocationi specifies the resources currently allocated to Pi  Needi specifies the additional resources that process Pi may still request to complete its task
  • 35. INTROOS Slides - ccsmwt Copyright© De La Salle University Professional Schools, Inc. College of Computer Studies Safety Algorithm 1. Let Work & Finish be vectors of length m & n, respectively. Initialize Work := Available & Finish [i] := false, for all processes Pi 2. Find an i such that a. Finish [i] = false, and b. Needi <= Work if no such i exists, go to step 4
  • 36. INTROOS Slides - ccsmwt Copyright© De La Salle University Professional Schools, Inc. College of Computer Studies Safety Algorithm 3. Work := Work + Allocationi Finish [i] = true go to step 2 4. If Finish[i] = true for all i, then the system is in a safe state
  • 37. INTROOS Slides - ccsmwt Copyright© De La Salle University Professional Schools, Inc. College of Computer Studies Resource Request Algorithm Let Requesti be the request vector for process Pi. If Requesti[j] = k, then Pi wants k instances of resource type Rj When a request for resources is made by process Pi, the ff actions are taken: 1. If Requesti <= Needi, go to step 2. Otherwise, raise an error condition, since the process has exceeded its max. claim
  • 38. INTROOS Slides - ccsmwt Copyright© De La Salle University Professional Schools, Inc. College of Computer Studies Resource Request Algorithm 2. If Requesti <= Available, go to step 3. Otherwise, Pi must wait, since the resources are not available 3. Have the system pretend to have allocated the requested resources to process Pi by modifying the state as follows: Available := Available - Requesti Allocation := Allocationi + Requesti Needi := Needi - Requesti
  • 39. INTROOS Slides - ccsmwt Copyright© De La Salle University Professional Schools, Inc. College of Computer Studies Resource Request Algorithm If the resulting resource allocation state is safe, the transaction is completed and process Pi is allocated its resources. However, if the new state is unsafe, then Pi must wait for Requesti and the old resource-allocation state is restored.
  • 40. INTROOS Slides - ccsmwt Copyright© De La Salle University Professional Schools, Inc. College of Computer Studies Example PROCESS Allocation Max Available A B C A B C A B C P0 0 1 0 7 5 3 3 3 2 P1 2 0 0 3 2 2 P2 3 0 2 9 0 2 P3 2 1 1 2 2 2 P4 0 0 2 4 3 3 Given 5 processes 3 resources A, B, C A = 10 instances B = 5 instances C = 7 instances 1. Request of P1 = (1,0,2) 2. Request of P4 = (3,3,0) 3. Request of P0 = (0,2,0)
  • 41. INTROOS Slides - ccsmwt Copyright© De La Salle University Professional Schools, Inc. College of Computer Studies Deadlock Detection If no deadlock prevention or avoidance algorithm is available, the system may have a deadlock situation System must provide:  Algorithm that examines the state of the system to determine whether a deadlock has occurred  Algorithm to recover from deadlock
  • 42. INTROOS Slides - ccsmwt Copyright© De La Salle University Professional Schools, Inc. College of Computer Studies Single Instance Resource Type Wait-for graph – same as RAG but remove the nodes of type resource & collapse the appropriate edges An edge from Pi to Pj in a WFG implies that process Pi is waiting for process Pj to release a resource that Pi needs An edge from Pi  Pj exists in a WFG iff the corresponding RAG contains 2 edges Pi Rq & Rq  Pj for some resource Rq
  • 43. INTROOS Slides - ccsmwt Copyright© De La Salle University Professional Schools, Inc. College of Computer Studies Example R3R1 P5 P3 R4 P2P1 P4 R5R2 Note: Deadlock exists iff the WFG contains a cycle
  • 44. INTROOS Slides - ccsmwt Copyright© De La Salle University Professional Schools, Inc. College of Computer Studies Several Instances Resource Type Data Structures Available - # of available resource type Allocation - # of resources of each type currently allocated to each process Request - n X m matrix that indicates the current request of each process
  • 45. INTROOS Slides - ccsmwt Copyright© De La Salle University Professional Schools, Inc. College of Computer Studies Algorithm 1. Let Work and Finish be vectors of length m & n, respectively. Initialize Work := Available. For i = 1,2,..,n, if Allocationi ≠ 0, then Finish[i]:= false; otherwise, Finish[i]:=true 2. Find an index i such that a. Finish [i] := false, and b. Requesti <= Work If no such i exists, go to step 4
  • 46. INTROOS Slides - ccsmwt Copyright© De La Salle University Professional Schools, Inc. College of Computer Studies Algorithm 3. Work := Work + Allocationi Finish[i] := true Go to step 2 4. If Finish[i] = false, for some i, 1 <= i <= n, then the system is in a Deadlock state. Moreover, if Finish[i] = false, then process Pi is deadlocked
  • 47. INTROOS Slides - ccsmwt Copyright© De La Salle University Professional Schools, Inc. College of Computer Studies Example 1 PROCES S Allocation Request Available A B C A B C A B C P0 0 1 0 0 0 0 0 0 0 P1 2 0 0 2 0 2 P2 3 0 3 0 0 0 P3 2 1 1 1 0 0 P4 0 0 2 0 0 2 Given 5 processes 3 resource types A,B,C A = 7 instances B = 2 instances C = 6 instances
  • 48. INTROOS Slides - ccsmwt Copyright© De La Salle University Professional Schools, Inc. College of Computer Studies Example 2 PROCES S Allocation Request Available A B C A B C A B C P0 0 1 0 0 0 0 0 0 0 P1 2 0 0 2 0 2 P2 3 0 3 0 0 1 P3 2 1 1 1 0 0 P4 0 0 2 0 0 2 Given 5 processes 3 resource types A,B,C A = 7 instances B = 2 instances C = 6 instances
  • 49. INTROOS Slides - ccsmwt Copyright© De La Salle University Professional Schools, Inc. College of Computer Studies Recovery from Deadlock Options: 1. Abort one or more processes 2. Preempt some resources from one or more of the deadlocked processes Process Termination 1. Abort all deadlocked processes 2. Abort one process at a time until the deadlock cycle is eliminated
  • 50. INTROOS Slides - ccsmwt Copyright© De La Salle University Professional Schools, Inc. College of Computer Studies Recovery from Deadlock Resource Preemption  Preempt some resources from processes & given theses resources to other processes until the deadlock cycle is broken Issues 1. Selecting a Victim 2. Rollback 3. Starvation