osy
osy
Deadlock Handling
Submitted by:
1
CERTIFICATE
Certified that this Micro-Project Report
Deadlock Handling
Is the work of
H.O.D – PRINCIPAL
2
Acknowledgement
We would also like to thank our Principal, HOD, and other faculty
members from our second-year department for their support and
motivation.
Finally, we have completed our micro project as per our syllabus and
department requirements. Once again, a big thank you to our respected
Principal, HOD, and faculty members for their help in completing the
project.
Thank you!
3
Abstract
4
Introduction
5
AGENDA
Deadlock
Deadlock Problem & Example- Bridge Crossing Problem
The cause, System Model & Normal Resource Allocation Operation
Necessary conditions for deadlock
Methods for handling Deadlock
Resource Allocation Graph (RAG)
Deadlock Prevention
Deadlock Avoidance
Recovery from Deadlock
DEADLOCK
DEADLOCK PROBLEM
6
Deadlock refers to a specific condition when two or more processes are each
waiting for each other to release a resource, or more than two processes are
waiting for resources in a circular chain.
Example
Client applications using the database may require exclusive access to
a table.
Two client applications C1 and C2.
If C1 holds lock on table, attempts to obtain on the other i.e., already
held by C2.
This may lead to deadlock if the C2 application then attempts to
obtain the lock that is held by the C1 application.
7
MORE EXAMPLES
“It takes money to make money.”
“You can't get a job without experience; you can't get
experience without a job.”
SYSTEM MODEL
A system consists of a finite no. of resources for no. of competing
processes:
Resource types R1, R2, . . ., Rm
CPU cycles, memory space, files and I/O devices
8
DEADLOCK CHARACTERIZATION
9
RESOURCE ALLOCATION GRAPH (RAG)
A visual (mathematical ) way to determine if a deadlock has, or may occur.
• G = ( V, E )The graph contains nodes and edges.
V Nodes consist of processes = { P1, P2, P3, ...} and resource
types { R1, R2, ...}
E Edges are (Pi, Rj) or (Ri, Pj)
• An arrow from the process to resource indicates the process is
requesting the resource. An arrow from resource to process shows an
instance of the resource has been allocated to the process.
• Process is a circle, resource type is square; dots represent number of
instances of resource in type. Request points to square,
assignment comes from dot.
If the graph contains no cycles, then no process is deadlocked.
• If there is a cycle, then:
If resource types have multiple instances per resource type, then
possibility of deadlock MAY exist.
If each resource type has one instance per resource type, then
deadlock has occurred.
10
Resource Allocation Graph Allocation Graph with a Cycle
with a Deadlock but No Deadlock Resource
DEADLOCK PREVENTION:
1. Mutual exclusion:
Automatically holds for printers and other non-sharables.
Shared entities (read only files) don't need mutual exclusion (and
aren’t susceptible to deadlock.)
Prevention not possible, since some devices are intrinsically non
sharable
11
3. No pre-emption:
Release any resource already being held if the process can't get an
additional resource.
Allow pre-emption - if a needed resource is held by another process,
which is also waiting on some resource, steal it. Otherwise wait.
4. Circular wait:
Number resources and only request in ascending order.
DEADLOCK AVOIDANCE
DEADLOCK AVOIDANCE(CON)
12
SAFE STATE
BANKER’S ALGORITHM
Multiple instances.
Each process claims maximum resource needs a priori.
When a process requests a resource it may have to wait.
When a process gets all of its resources it must return them in a
finite amount of time.
13
CONCLUSION
14