SlideShare a Scribd company logo
1 of 16
Introduction
What are Deadlocks ? ‘ Any blocked process which cannot be
resolved unless there is some outside intervention’.
In operating system deadlocks can be visualized where processes
have some resources held by them and are waiting for some resources
to fulfill their completion which are instead being held by some other
blocked process.
A very simple real-world example is of the two cars halted on
both sides of a bridge which has only width for one car to pass. As both
cars are holding each end of the bridge so neither can pass unless and
until one car backs up and clears the road so that the other car pass and
vice versa.
Deadlock Classification
Mutual Exclusion : If one process is holding a resource required by other
processes that resource must wait until it is released by the process.
Hold and Wait : Processes are allowed to hold one or more resources and
waiting for additional resources held by other processes.
No Pre-Emption : Resources are released voluntarily, neither another process
nor the OS can force a process to release a resource.
Circular Wait : There may exist a set of waiting processes such that P0 is
waiting for a resource held by P1, P1 is waiting for a resource held by P2,… Pn-
1 is waiting for a resource held by Pn, and Pn is waiting for a resource held by
P0.
Resource Allocation Graph
We can model deadlock conditions using a directed graph called a Resource Allocation Graph (RAG).
Lets understand some basics:
Two Kinds of Nodes :
Boxes : Represent Resources
Circles : Represent Processes
Two Kinds of (Directed) Edges:
Request Edge : from thread to resource, indicates that the thread has requested the resource and is
waiting to acquire it.
Assignment Edge : from resource instance to thread, indicates the thread is holding the resource
instance.
When a request is made, a request edge is added
On fulfillment the request edge is transformed into and assignment edge.
When a resource is released by a process, the assignment edge is deleted.
RAG with Single Resource Instance
R1 R2 R1 R2
P1 P2 P3
R3 R4
P1 P2 P3
R3 R4
A closed cycle in RAG with single resource instance is mandatory for deadlock.
RAG with Multiple Resource Instances
R1 R2 R1 R2
P1 P2 P3
R3 R4
P1 P2 P3
R3 R4
A Knot is mandatory for a deadlock. (Knot is created when strongly connected
subgraphs with no outgoing edges are formed).
Prevention and Avoidance
Prevention by eliminating one of the four conditions
Acquire all resources before proceeding (No wait while Hold)
Allow Preemption (Eliminate 3d Condition)
Prioritize Processes and Assign Resources in order of Priorities (No Circular
Wait)
Avoidance can be done by allowing resource requests only if they don’t lead to
deadlock condition. In other words, Safe state : An order to entertain resource
requests so that all processes can be completed.
Drawbacks:
Resource requirements for all processes must be known in advance.
Resource request set is known and fixed,
Complex Analysis for every request.
Deadlock Detection
Detection :
Issues
Maintenance of WFG (Wait for Graphs)
Search of WFG for deadlocks
Requirements
Progress No undetected deadlocks
Safety No false(phantom) deadlocks
Resolution
Roll Back one or more processes to break dependencies in WFG to resolve the
situation.
Single Instance for Each
Resource Type
Maintain wait-for Graph
Nodes are processes
Pi-> Pj if Pi is waiting for Pj
Periodically invoke an algorithm that searches for a cycle in the graph. If
there is a cycle then there is or will be a deadlock.
An algorithm to detect a cycle in graph requires an order of n2
Operations, where n is the number of vertices in the graph.
RAG& WFG
R1 R4
P1 P2 P3
P5
R3
P4 R5
R2
P1 P2 P3
P5
P4
Corresponding Wait for Graph
Resource Allocation Graph
Several Instances of a Resource
Type
Available : A vector of length m indicates the number of available
resources of each type.
Allocation: An n x m matrix defines the number of resources of each type
currently allocated to each process.
Request: An n x m matrix indicates the current request of each process.
If Request[ij]=k, then process Pi is requesting k more instances of
resource type Rj.
Detection Algorithm
1. Let Work and Finish be vectors of length m and n, respectively
Initialize :
(a) Work=Available
(b) For i=1,2,…,n if Allocationi ≠ 0, then
Finish[i]=false; otherwise, Finish[i]=true.
2. Find an index i such that both:
(a) Finish[i]==false
(b) Requesti≤ Work
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 the deadlock
state. Moreover, if Finish[i]==false, then Piis deadlocked.
Algorithm requires an order of O(m x n2) operations to detect whether the system is in
deadlocked state.
Example of Detection Algorithm
Five processes Po through P4; three resource types A(7 instances), B(2
instances), and C(6 instances).
Snapshot at time T0:
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
Sequence <P0,P1,P2,P3,P4>will result in Finish[i]=true for all i.
P2 request an additional instance of type C.
Request
A B C
P0 0 0 0
P1 2 0 1
P2 0 0 1
P3 1 0 0
P4 0 0 2
State of System?
Can reclaim resources held by process P0, but insufficient
resources to fulfill other processes; requests.
Deadlock exists, consisting of processes P1,P2,P3 and P4.
Detection-Algorithm Usage
When, and how often, to invoke depends on:
How often a deadlock is likely to occur?
How many processes will need to be rolled back?
One for each disjoint cycle.
If detection algorithm is invoked arbitrarily, there may be many cycles in
the resource graph and so we would not be able to tell which of the
many deadlocked processes “caused” the deadlock.
Thank You

More Related Content

Similar to Deadlock Detection Algorithm

Section07-Deadlocks (1).ppt
Section07-Deadlocks (1).pptSection07-Deadlocks (1).ppt
Section07-Deadlocks (1).pptamadayshwan
 
FP 202 Chapter 2 - Part 3
FP 202 Chapter 2 - Part 3FP 202 Chapter 2 - Part 3
FP 202 Chapter 2 - Part 3rohassanie
 
Deadlock Detection.pptx
Deadlock Detection.pptxDeadlock Detection.pptx
Deadlock Detection.pptxinfomerlin
 
Deadlocks 160928121516-160928183232
Deadlocks 160928121516-160928183232Deadlocks 160928121516-160928183232
Deadlocks 160928121516-160928183232marangburu42
 
Process Synchronization And Deadlocks
Process Synchronization And DeadlocksProcess Synchronization And Deadlocks
Process Synchronization And Deadlockstech2click
 
CSS430_Deadlock.pptx
CSS430_Deadlock.pptxCSS430_Deadlock.pptx
CSS430_Deadlock.pptxamadayshwan
 
Os6 2
Os6 2Os6 2
Os6 2issbp
 
Galvin-operating System(Ch8)
Galvin-operating System(Ch8)Galvin-operating System(Ch8)
Galvin-operating System(Ch8)dsuyal1
 
osvzjsjjdndnnssnnsnsndndndnndeadlock.pptx
osvzjsjjdndnnssnnsnsndndndnndeadlock.pptxosvzjsjjdndnnssnnsnsndndndnndeadlock.pptx
osvzjsjjdndnnssnnsnsndndndnndeadlock.pptxBhaskar271887
 

Similar to Deadlock Detection Algorithm (20)

Section07-Deadlocks (1).ppt
Section07-Deadlocks (1).pptSection07-Deadlocks (1).ppt
Section07-Deadlocks (1).ppt
 
Deadlock
DeadlockDeadlock
Deadlock
 
FP 202 Chapter 2 - Part 3
FP 202 Chapter 2 - Part 3FP 202 Chapter 2 - Part 3
FP 202 Chapter 2 - Part 3
 
Dead lock
Dead lockDead lock
Dead lock
 
OS_Ch8
OS_Ch8OS_Ch8
OS_Ch8
 
OSCh8
OSCh8OSCh8
OSCh8
 
Deadlock Detection.pptx
Deadlock Detection.pptxDeadlock Detection.pptx
Deadlock Detection.pptx
 
Deadlocks
 Deadlocks Deadlocks
Deadlocks
 
Chapter 7 - Deadlocks
Chapter 7 - DeadlocksChapter 7 - Deadlocks
Chapter 7 - Deadlocks
 
Deadlocks 160928121516-160928183232
Deadlocks 160928121516-160928183232Deadlocks 160928121516-160928183232
Deadlocks 160928121516-160928183232
 
Deadlocks.ppt
Deadlocks.pptDeadlocks.ppt
Deadlocks.ppt
 
6. Deadlock.ppt
6. Deadlock.ppt6. Deadlock.ppt
6. Deadlock.ppt
 
Process Synchronization And Deadlocks
Process Synchronization And DeadlocksProcess Synchronization And Deadlocks
Process Synchronization And Deadlocks
 
CSS430_Deadlock.pptx
CSS430_Deadlock.pptxCSS430_Deadlock.pptx
CSS430_Deadlock.pptx
 
Dead Lock
Dead LockDead Lock
Dead Lock
 
Os6 2
Os6 2Os6 2
Os6 2
 
Galvin-operating System(Ch8)
Galvin-operating System(Ch8)Galvin-operating System(Ch8)
Galvin-operating System(Ch8)
 
OS - Deadlock
OS - DeadlockOS - Deadlock
OS - Deadlock
 
Os unit 4
Os unit 4Os unit 4
Os unit 4
 
osvzjsjjdndnnssnnsnsndndndnndeadlock.pptx
osvzjsjjdndnnssnnsnsndndndnndeadlock.pptxosvzjsjjdndnnssnnsnsndndndnndeadlock.pptx
osvzjsjjdndnnssnnsnsndndndnndeadlock.pptx
 

More from Mohammad Qureshi

Technical specification software fiscal device 1.1 pra
Technical specification software fiscal device 1.1 praTechnical specification software fiscal device 1.1 pra
Technical specification software fiscal device 1.1 praMohammad Qureshi
 
Presentation on Eductaion for BSEd
Presentation on Eductaion for BSEdPresentation on Eductaion for BSEd
Presentation on Eductaion for BSEdMohammad Qureshi
 
Final Project Master In Computer Sciences
Final Project Master In Computer SciencesFinal Project Master In Computer Sciences
Final Project Master In Computer SciencesMohammad Qureshi
 
Supply Chain Management System
Supply Chain Management SystemSupply Chain Management System
Supply Chain Management SystemMohammad Qureshi
 
Maple Leaf Cement Factory Ltd, Iskendarabad, Distt: Mianwali
Maple Leaf Cement Factory Ltd, Iskendarabad, Distt: MianwaliMaple Leaf Cement Factory Ltd, Iskendarabad, Distt: Mianwali
Maple Leaf Cement Factory Ltd, Iskendarabad, Distt: MianwaliMohammad Qureshi
 

More from Mohammad Qureshi (15)

Presentation.pptx
Presentation.pptxPresentation.pptx
Presentation.pptx
 
Technical specification software fiscal device 1.1 pra
Technical specification software fiscal device 1.1 praTechnical specification software fiscal device 1.1 pra
Technical specification software fiscal device 1.1 pra
 
Presentation on Eductaion for BSEd
Presentation on Eductaion for BSEdPresentation on Eductaion for BSEd
Presentation on Eductaion for BSEd
 
Resignation
ResignationResignation
Resignation
 
Ptcl Modem User Manual
Ptcl Modem User Manual Ptcl Modem User Manual
Ptcl Modem User Manual
 
C++notes
C++notesC++notes
C++notes
 
Qacojone The mystery
Qacojone The mysteryQacojone The mystery
Qacojone The mystery
 
Final project(vb)
Final project(vb)Final project(vb)
Final project(vb)
 
Installing (oracle8.05)
Installing (oracle8.05)Installing (oracle8.05)
Installing (oracle8.05)
 
Installing (deveoper6i)
Installing (deveoper6i)Installing (deveoper6i)
Installing (deveoper6i)
 
Situation2
Situation2Situation2
Situation2
 
Final Project Master In Computer Sciences
Final Project Master In Computer SciencesFinal Project Master In Computer Sciences
Final Project Master In Computer Sciences
 
Muhammad Nasir Qureshi
Muhammad Nasir QureshiMuhammad Nasir Qureshi
Muhammad Nasir Qureshi
 
Supply Chain Management System
Supply Chain Management SystemSupply Chain Management System
Supply Chain Management System
 
Maple Leaf Cement Factory Ltd, Iskendarabad, Distt: Mianwali
Maple Leaf Cement Factory Ltd, Iskendarabad, Distt: MianwaliMaple Leaf Cement Factory Ltd, Iskendarabad, Distt: Mianwali
Maple Leaf Cement Factory Ltd, Iskendarabad, Distt: Mianwali
 

Recently uploaded

The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 

Recently uploaded (20)

The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 

Deadlock Detection Algorithm

  • 1.
  • 2. Introduction What are Deadlocks ? ‘ Any blocked process which cannot be resolved unless there is some outside intervention’. In operating system deadlocks can be visualized where processes have some resources held by them and are waiting for some resources to fulfill their completion which are instead being held by some other blocked process. A very simple real-world example is of the two cars halted on both sides of a bridge which has only width for one car to pass. As both cars are holding each end of the bridge so neither can pass unless and until one car backs up and clears the road so that the other car pass and vice versa.
  • 3. Deadlock Classification Mutual Exclusion : If one process is holding a resource required by other processes that resource must wait until it is released by the process. Hold and Wait : Processes are allowed to hold one or more resources and waiting for additional resources held by other processes. No Pre-Emption : Resources are released voluntarily, neither another process nor the OS can force a process to release a resource. Circular Wait : There may exist a set of waiting processes such that P0 is waiting for a resource held by P1, P1 is waiting for a resource held by P2,… Pn- 1 is waiting for a resource held by Pn, and Pn is waiting for a resource held by P0.
  • 4. Resource Allocation Graph We can model deadlock conditions using a directed graph called a Resource Allocation Graph (RAG). Lets understand some basics: Two Kinds of Nodes : Boxes : Represent Resources Circles : Represent Processes Two Kinds of (Directed) Edges: Request Edge : from thread to resource, indicates that the thread has requested the resource and is waiting to acquire it. Assignment Edge : from resource instance to thread, indicates the thread is holding the resource instance. When a request is made, a request edge is added On fulfillment the request edge is transformed into and assignment edge. When a resource is released by a process, the assignment edge is deleted.
  • 5. RAG with Single Resource Instance R1 R2 R1 R2 P1 P2 P3 R3 R4 P1 P2 P3 R3 R4 A closed cycle in RAG with single resource instance is mandatory for deadlock.
  • 6. RAG with Multiple Resource Instances R1 R2 R1 R2 P1 P2 P3 R3 R4 P1 P2 P3 R3 R4 A Knot is mandatory for a deadlock. (Knot is created when strongly connected subgraphs with no outgoing edges are formed).
  • 7. Prevention and Avoidance Prevention by eliminating one of the four conditions Acquire all resources before proceeding (No wait while Hold) Allow Preemption (Eliminate 3d Condition) Prioritize Processes and Assign Resources in order of Priorities (No Circular Wait) Avoidance can be done by allowing resource requests only if they don’t lead to deadlock condition. In other words, Safe state : An order to entertain resource requests so that all processes can be completed. Drawbacks: Resource requirements for all processes must be known in advance. Resource request set is known and fixed, Complex Analysis for every request.
  • 8. Deadlock Detection Detection : Issues Maintenance of WFG (Wait for Graphs) Search of WFG for deadlocks Requirements Progress No undetected deadlocks Safety No false(phantom) deadlocks Resolution Roll Back one or more processes to break dependencies in WFG to resolve the situation.
  • 9. Single Instance for Each Resource Type Maintain wait-for Graph Nodes are processes Pi-> Pj if Pi is waiting for Pj Periodically invoke an algorithm that searches for a cycle in the graph. If there is a cycle then there is or will be a deadlock. An algorithm to detect a cycle in graph requires an order of n2 Operations, where n is the number of vertices in the graph.
  • 10. RAG& WFG R1 R4 P1 P2 P3 P5 R3 P4 R5 R2 P1 P2 P3 P5 P4 Corresponding Wait for Graph Resource Allocation Graph
  • 11. Several Instances of a Resource Type Available : A vector of length m indicates the number of available resources of each type. Allocation: An n x m matrix defines the number of resources of each type currently allocated to each process. Request: An n x m matrix indicates the current request of each process. If Request[ij]=k, then process Pi is requesting k more instances of resource type Rj.
  • 12. Detection Algorithm 1. Let Work and Finish be vectors of length m and n, respectively Initialize : (a) Work=Available (b) For i=1,2,…,n if Allocationi ≠ 0, then Finish[i]=false; otherwise, Finish[i]=true. 2. Find an index i such that both: (a) Finish[i]==false (b) Requesti≤ Work 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 the deadlock state. Moreover, if Finish[i]==false, then Piis deadlocked. Algorithm requires an order of O(m x n2) operations to detect whether the system is in deadlocked state.
  • 13. Example of Detection Algorithm Five processes Po through P4; three resource types A(7 instances), B(2 instances), and C(6 instances). Snapshot at time T0: 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 Sequence <P0,P1,P2,P3,P4>will result in Finish[i]=true for all i.
  • 14. P2 request an additional instance of type C. Request A B C P0 0 0 0 P1 2 0 1 P2 0 0 1 P3 1 0 0 P4 0 0 2 State of System? Can reclaim resources held by process P0, but insufficient resources to fulfill other processes; requests. Deadlock exists, consisting of processes P1,P2,P3 and P4.
  • 15. Detection-Algorithm Usage When, and how often, to invoke depends on: How often a deadlock is likely to occur? How many processes will need to be rolled back? One for each disjoint cycle. If detection algorithm is invoked arbitrarily, there may be many cycles in the resource graph and so we would not be able to tell which of the many deadlocked processes “caused” the deadlock.