SlideShare a Scribd company logo
1 of 25
Deadlocks
CS4532 Concurrent Programming
Dilum Bandara
Dilum.Bandara@uom.lk
Slides extended from “Modern Operating Systems” by A. S. Tanenbaum
Resources
 Examples of computer resources
 Printers, tape drives, tables
 Processes need access to resources in
reasonable order
 Suppose a process holds resource T & requests
resource U, at same time another process holds
U & requests T
 Both are blocked & remain so
2
Resources (Cont.)
 Deadlocks occur when …
 Processes are granted exclusive access to
devices/resources
 Sequence of events required to use a resource
 Request, use, & release
 Must wait, if request is denied
 Requesting process may be blocked or may fail
3
2 Types of Resources
 Preemptable resources
 Can be taken away from a process with no ill effects
 Nonpreemptable resources
 Will cause the process to fail, if taken away
4
Deadlocks
 Formal definition
 Set of processes is deadlocked, if each process in the
set is waiting for an event that only another process in
the set can cause
 Usually the event is release of a currently held
resource
 None of the processes can …
 Run
 Release resources
 Be awakened
5
4 Conditions for Deadlock
1. Mutual exclusion condition
 Each resource assigned to 1 process or is available
2. Hold & wait condition
 Process holding resources can request additional
3. No preemption condition
 Previously granted resources cannot be forcibly taken
away
4. Circular wait condition
 Must be a circular chain of 2 or more processes
 Each is waiting for a resource held by next member of
the chain
6
Deadlock Modeling
 Modeled with directed graphs
 Resource R assigned to process A
 Process B is requesting/waiting for resource S
 Process C & D are in deadlock over resources T & U
7
Strategies for Dealing with Deadlocks
 Just ignore the problem altogether
 Detection & recovery
 Dynamic avoidance
 Careful resource allocation
 Prevention
 Negating one of the 4 necessary conditions
8
1. Ostrich Algorithm
 Pretend there is no problem
 Reasonable if
 Deadlocks occur very rarely
 Cost of prevention is high
 UNIX & Windows takes this approach
 It is a tradeoff between
 Convenience
 Correctness
9
2. Detection with One Resource of Each Type
 Note resource ownership & requests
 A cycle can be found within the graph, denoting
deadlock
10
Detection with One Resource of Each
Type (Cont.)
 Data structures needed by deadlock detection
algorithm
11
Example – Detection with One
Resource of Each Type
12
Recovery From Deadlock
 Recovery through preemption
 Take a resource from some other process
 Depends on nature of resource
 Recovery through rollback
 Checkpoint a process periodically
 Use this saved state
 Restart process, if it is found deadlocked
 Recovery through killing processes
 Kill one of the processes in deadlock cycle
 Other processes get its resources
 Choose process that can be rerun from the beginning
13
Example – How Deadlock Occurs?
14
(o) (p) (q)
3. How Deadlock Can be Avoided?
15
Deadlock Avoidance – Resource
Trajectories
 2 process resource trajectories
16
Safe & Unsafe States – Banker’s
Algorithm
Demonstration that the state in (a) is safe
17
(a) (b) (c) (d) (e)
(a) (b) (c) (d)
Demonstration that the sate in (b) is not safe
Banker’s Algorithm for Multiple
Resources
18
4. Deadlock Prevention
 Attacking Mutual Exclusion Condition
 Attacking Hold & Wait Condition
 Attacking No Preemption Condition
 Attacking Circular Wait Condition
19
Attacking Mutual Exclusion Condition
 Some devices (such as printer) can be spooled
 Only printer daemon uses printer resource
 Thus, deadlock for printer eliminated
 Not all devices can be spooled
 Principle
 Avoid assigning resources when not absolutely
necessary
 As few processes as possible actually claim the
resource
20
Attacking Hold & Wait Condition
 Require processes to request resources before
starting
 A process never has to wait for what it needs
 Problems
 May not know required resources at start of run
 Ties up resources other processes could be using
 Variation
 Process must give up all resources
 Then request all immediately needed
21
Attacking No Preemption Condition
 This is not a viable option
 Consider a process given the printer
 Halfway through its job
 Now forcibly take away printer
 !!??
22
Attacking Circular Wait Condition
 Normally ordered resources
 Resource graph
23
(a) (b)
Summary of Deadlock Prevention
Approaches
24
Dealing with Deadlocks – Summary
25
Dealing with Deadlocks
Just Ignore
Detection &
Recovery
Preemption
Rollback
Kill
Avoidance
Banker’s
Algorithm
Prevention
Spooling
Request All
Together
Take Away
Order
Numerically

More Related Content

Similar to Deadlocks

Os case study word
Os case study wordOs case study word
Os case study wordDhol Yash
 
Deadlock and memory management -- Operating System
Deadlock and memory management -- Operating SystemDeadlock and memory management -- Operating System
Deadlock and memory management -- Operating SystemEktaVaswani2
 
Mch7 deadlock
Mch7 deadlockMch7 deadlock
Mch7 deadlockwahab13
 
FP 202 Chapter 2 - Part 3
FP 202 Chapter 2 - Part 3FP 202 Chapter 2 - Part 3
FP 202 Chapter 2 - Part 3rohassanie
 
Deadlocks prefinal
Deadlocks prefinalDeadlocks prefinal
Deadlocks prefinalmarangburu42
 
Deadlocksprefinal 161014115456
Deadlocksprefinal 161014115456Deadlocksprefinal 161014115456
Deadlocksprefinal 161014115456marangburu42
 
Process Synchronization And Deadlocks
Process Synchronization And DeadlocksProcess Synchronization And Deadlocks
Process Synchronization And Deadlockstech2click
 
Deadlocks 160928121516-160928183232
Deadlocks 160928121516-160928183232Deadlocks 160928121516-160928183232
Deadlocks 160928121516-160928183232marangburu42
 
OS Lecture 5.ppt
OS Lecture 5.pptOS Lecture 5.ppt
OS Lecture 5.pptleeelito
 
Deadlock detection & prevention
Deadlock detection & preventionDeadlock detection & prevention
Deadlock detection & preventionIkhtiarUddinShaHin
 
Deadlock in Operating System
Deadlock in Operating SystemDeadlock in Operating System
Deadlock in Operating SystemSanthiNivas
 
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
 
Deadlock in Operating System
Deadlock in Operating SystemDeadlock in Operating System
Deadlock in Operating SystemAUST
 

Similar to Deadlocks (20)

Os case study word
Os case study wordOs case study word
Os case study word
 
Operating system Deadlock
Operating system DeadlockOperating system Deadlock
Operating system Deadlock
 
Gp1242 007 oer ppt
Gp1242 007 oer pptGp1242 007 oer ppt
Gp1242 007 oer ppt
 
OS-Part-06.pdf
OS-Part-06.pdfOS-Part-06.pdf
OS-Part-06.pdf
 
Deadlock and memory management -- Operating System
Deadlock and memory management -- Operating SystemDeadlock and memory management -- Operating System
Deadlock and memory management -- Operating System
 
10. deadlock
10. deadlock10. deadlock
10. deadlock
 
Mch7 deadlock
Mch7 deadlockMch7 deadlock
Mch7 deadlock
 
FP 202 Chapter 2 - Part 3
FP 202 Chapter 2 - Part 3FP 202 Chapter 2 - Part 3
FP 202 Chapter 2 - Part 3
 
Deadlock
DeadlockDeadlock
Deadlock
 
Deadlocks prefinal
Deadlocks prefinalDeadlocks prefinal
Deadlocks prefinal
 
Deadlocksprefinal 161014115456
Deadlocksprefinal 161014115456Deadlocksprefinal 161014115456
Deadlocksprefinal 161014115456
 
Process Synchronization And Deadlocks
Process Synchronization And DeadlocksProcess Synchronization And Deadlocks
Process Synchronization And Deadlocks
 
Deadlocks 160928121516-160928183232
Deadlocks 160928121516-160928183232Deadlocks 160928121516-160928183232
Deadlocks 160928121516-160928183232
 
OS Lecture 5.ppt
OS Lecture 5.pptOS Lecture 5.ppt
OS Lecture 5.ppt
 
Deadlocks
DeadlocksDeadlocks
Deadlocks
 
Deadlock detection & prevention
Deadlock detection & preventionDeadlock detection & prevention
Deadlock detection & prevention
 
Deadlock in Operating System
Deadlock in Operating SystemDeadlock in Operating System
Deadlock in Operating System
 
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...
 
Deadlocks
Deadlocks Deadlocks
Deadlocks
 
Deadlock in Operating System
Deadlock in Operating SystemDeadlock in Operating System
Deadlock in Operating System
 

More from Dilum Bandara

Introduction to Machine Learning
Introduction to Machine LearningIntroduction to Machine Learning
Introduction to Machine LearningDilum Bandara
 
Time Series Analysis and Forecasting in Practice
Time Series Analysis and Forecasting in PracticeTime Series Analysis and Forecasting in Practice
Time Series Analysis and Forecasting in PracticeDilum Bandara
 
Introduction to Dimension Reduction with PCA
Introduction to Dimension Reduction with PCAIntroduction to Dimension Reduction with PCA
Introduction to Dimension Reduction with PCADilum Bandara
 
Introduction to Descriptive & Predictive Analytics
Introduction to Descriptive & Predictive AnalyticsIntroduction to Descriptive & Predictive Analytics
Introduction to Descriptive & Predictive AnalyticsDilum Bandara
 
Introduction to Concurrent Data Structures
Introduction to Concurrent Data StructuresIntroduction to Concurrent Data Structures
Introduction to Concurrent Data StructuresDilum Bandara
 
Hard to Paralelize Problems: Matrix-Vector and Matrix-Matrix
Hard to Paralelize Problems: Matrix-Vector and Matrix-MatrixHard to Paralelize Problems: Matrix-Vector and Matrix-Matrix
Hard to Paralelize Problems: Matrix-Vector and Matrix-MatrixDilum Bandara
 
Introduction to Map-Reduce Programming with Hadoop
Introduction to Map-Reduce Programming with HadoopIntroduction to Map-Reduce Programming with Hadoop
Introduction to Map-Reduce Programming with HadoopDilum Bandara
 
Embarrassingly/Delightfully Parallel Problems
Embarrassingly/Delightfully Parallel ProblemsEmbarrassingly/Delightfully Parallel Problems
Embarrassingly/Delightfully Parallel ProblemsDilum Bandara
 
Introduction to Warehouse-Scale Computers
Introduction to Warehouse-Scale ComputersIntroduction to Warehouse-Scale Computers
Introduction to Warehouse-Scale ComputersDilum Bandara
 
Introduction to Thread Level Parallelism
Introduction to Thread Level ParallelismIntroduction to Thread Level Parallelism
Introduction to Thread Level ParallelismDilum Bandara
 
CPU Memory Hierarchy and Caching Techniques
CPU Memory Hierarchy and Caching TechniquesCPU Memory Hierarchy and Caching Techniques
CPU Memory Hierarchy and Caching TechniquesDilum Bandara
 
Data-Level Parallelism in Microprocessors
Data-Level Parallelism in MicroprocessorsData-Level Parallelism in Microprocessors
Data-Level Parallelism in MicroprocessorsDilum Bandara
 
Instruction Level Parallelism – Hardware Techniques
Instruction Level Parallelism – Hardware TechniquesInstruction Level Parallelism – Hardware Techniques
Instruction Level Parallelism – Hardware TechniquesDilum Bandara
 
Instruction Level Parallelism – Compiler Techniques
Instruction Level Parallelism – Compiler TechniquesInstruction Level Parallelism – Compiler Techniques
Instruction Level Parallelism – Compiler TechniquesDilum Bandara
 
CPU Pipelining and Hazards - An Introduction
CPU Pipelining and Hazards - An IntroductionCPU Pipelining and Hazards - An Introduction
CPU Pipelining and Hazards - An IntroductionDilum Bandara
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
High Performance Networking with Advanced TCP
High Performance Networking with Advanced TCPHigh Performance Networking with Advanced TCP
High Performance Networking with Advanced TCPDilum Bandara
 
Introduction to Content Delivery Networks
Introduction to Content Delivery NetworksIntroduction to Content Delivery Networks
Introduction to Content Delivery NetworksDilum Bandara
 
Peer-to-Peer Networking Systems and Streaming
Peer-to-Peer Networking Systems and StreamingPeer-to-Peer Networking Systems and Streaming
Peer-to-Peer Networking Systems and StreamingDilum Bandara
 

More from Dilum Bandara (20)

Introduction to Machine Learning
Introduction to Machine LearningIntroduction to Machine Learning
Introduction to Machine Learning
 
Time Series Analysis and Forecasting in Practice
Time Series Analysis and Forecasting in PracticeTime Series Analysis and Forecasting in Practice
Time Series Analysis and Forecasting in Practice
 
Introduction to Dimension Reduction with PCA
Introduction to Dimension Reduction with PCAIntroduction to Dimension Reduction with PCA
Introduction to Dimension Reduction with PCA
 
Introduction to Descriptive & Predictive Analytics
Introduction to Descriptive & Predictive AnalyticsIntroduction to Descriptive & Predictive Analytics
Introduction to Descriptive & Predictive Analytics
 
Introduction to Concurrent Data Structures
Introduction to Concurrent Data StructuresIntroduction to Concurrent Data Structures
Introduction to Concurrent Data Structures
 
Hard to Paralelize Problems: Matrix-Vector and Matrix-Matrix
Hard to Paralelize Problems: Matrix-Vector and Matrix-MatrixHard to Paralelize Problems: Matrix-Vector and Matrix-Matrix
Hard to Paralelize Problems: Matrix-Vector and Matrix-Matrix
 
Introduction to Map-Reduce Programming with Hadoop
Introduction to Map-Reduce Programming with HadoopIntroduction to Map-Reduce Programming with Hadoop
Introduction to Map-Reduce Programming with Hadoop
 
Embarrassingly/Delightfully Parallel Problems
Embarrassingly/Delightfully Parallel ProblemsEmbarrassingly/Delightfully Parallel Problems
Embarrassingly/Delightfully Parallel Problems
 
Introduction to Warehouse-Scale Computers
Introduction to Warehouse-Scale ComputersIntroduction to Warehouse-Scale Computers
Introduction to Warehouse-Scale Computers
 
Introduction to Thread Level Parallelism
Introduction to Thread Level ParallelismIntroduction to Thread Level Parallelism
Introduction to Thread Level Parallelism
 
CPU Memory Hierarchy and Caching Techniques
CPU Memory Hierarchy and Caching TechniquesCPU Memory Hierarchy and Caching Techniques
CPU Memory Hierarchy and Caching Techniques
 
Data-Level Parallelism in Microprocessors
Data-Level Parallelism in MicroprocessorsData-Level Parallelism in Microprocessors
Data-Level Parallelism in Microprocessors
 
Instruction Level Parallelism – Hardware Techniques
Instruction Level Parallelism – Hardware TechniquesInstruction Level Parallelism – Hardware Techniques
Instruction Level Parallelism – Hardware Techniques
 
Instruction Level Parallelism – Compiler Techniques
Instruction Level Parallelism – Compiler TechniquesInstruction Level Parallelism – Compiler Techniques
Instruction Level Parallelism – Compiler Techniques
 
CPU Pipelining and Hazards - An Introduction
CPU Pipelining and Hazards - An IntroductionCPU Pipelining and Hazards - An Introduction
CPU Pipelining and Hazards - An Introduction
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
High Performance Networking with Advanced TCP
High Performance Networking with Advanced TCPHigh Performance Networking with Advanced TCP
High Performance Networking with Advanced TCP
 
Introduction to Content Delivery Networks
Introduction to Content Delivery NetworksIntroduction to Content Delivery Networks
Introduction to Content Delivery Networks
 
Peer-to-Peer Networking Systems and Streaming
Peer-to-Peer Networking Systems and StreamingPeer-to-Peer Networking Systems and Streaming
Peer-to-Peer Networking Systems and Streaming
 
Mobile Services
Mobile ServicesMobile Services
Mobile Services
 

Recently uploaded

Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 

Recently uploaded (20)

Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 

Deadlocks

  • 1. Deadlocks CS4532 Concurrent Programming Dilum Bandara Dilum.Bandara@uom.lk Slides extended from “Modern Operating Systems” by A. S. Tanenbaum
  • 2. Resources  Examples of computer resources  Printers, tape drives, tables  Processes need access to resources in reasonable order  Suppose a process holds resource T & requests resource U, at same time another process holds U & requests T  Both are blocked & remain so 2
  • 3. Resources (Cont.)  Deadlocks occur when …  Processes are granted exclusive access to devices/resources  Sequence of events required to use a resource  Request, use, & release  Must wait, if request is denied  Requesting process may be blocked or may fail 3
  • 4. 2 Types of Resources  Preemptable resources  Can be taken away from a process with no ill effects  Nonpreemptable resources  Will cause the process to fail, if taken away 4
  • 5. Deadlocks  Formal definition  Set of processes is deadlocked, if each process in the set is waiting for an event that only another process in the set can cause  Usually the event is release of a currently held resource  None of the processes can …  Run  Release resources  Be awakened 5
  • 6. 4 Conditions for Deadlock 1. Mutual exclusion condition  Each resource assigned to 1 process or is available 2. Hold & wait condition  Process holding resources can request additional 3. No preemption condition  Previously granted resources cannot be forcibly taken away 4. Circular wait condition  Must be a circular chain of 2 or more processes  Each is waiting for a resource held by next member of the chain 6
  • 7. Deadlock Modeling  Modeled with directed graphs  Resource R assigned to process A  Process B is requesting/waiting for resource S  Process C & D are in deadlock over resources T & U 7
  • 8. Strategies for Dealing with Deadlocks  Just ignore the problem altogether  Detection & recovery  Dynamic avoidance  Careful resource allocation  Prevention  Negating one of the 4 necessary conditions 8
  • 9. 1. Ostrich Algorithm  Pretend there is no problem  Reasonable if  Deadlocks occur very rarely  Cost of prevention is high  UNIX & Windows takes this approach  It is a tradeoff between  Convenience  Correctness 9
  • 10. 2. Detection with One Resource of Each Type  Note resource ownership & requests  A cycle can be found within the graph, denoting deadlock 10
  • 11. Detection with One Resource of Each Type (Cont.)  Data structures needed by deadlock detection algorithm 11
  • 12. Example – Detection with One Resource of Each Type 12
  • 13. Recovery From Deadlock  Recovery through preemption  Take a resource from some other process  Depends on nature of resource  Recovery through rollback  Checkpoint a process periodically  Use this saved state  Restart process, if it is found deadlocked  Recovery through killing processes  Kill one of the processes in deadlock cycle  Other processes get its resources  Choose process that can be rerun from the beginning 13
  • 14. Example – How Deadlock Occurs? 14
  • 15. (o) (p) (q) 3. How Deadlock Can be Avoided? 15
  • 16. Deadlock Avoidance – Resource Trajectories  2 process resource trajectories 16
  • 17. Safe & Unsafe States – Banker’s Algorithm Demonstration that the state in (a) is safe 17 (a) (b) (c) (d) (e) (a) (b) (c) (d) Demonstration that the sate in (b) is not safe
  • 18. Banker’s Algorithm for Multiple Resources 18
  • 19. 4. Deadlock Prevention  Attacking Mutual Exclusion Condition  Attacking Hold & Wait Condition  Attacking No Preemption Condition  Attacking Circular Wait Condition 19
  • 20. Attacking Mutual Exclusion Condition  Some devices (such as printer) can be spooled  Only printer daemon uses printer resource  Thus, deadlock for printer eliminated  Not all devices can be spooled  Principle  Avoid assigning resources when not absolutely necessary  As few processes as possible actually claim the resource 20
  • 21. Attacking Hold & Wait Condition  Require processes to request resources before starting  A process never has to wait for what it needs  Problems  May not know required resources at start of run  Ties up resources other processes could be using  Variation  Process must give up all resources  Then request all immediately needed 21
  • 22. Attacking No Preemption Condition  This is not a viable option  Consider a process given the printer  Halfway through its job  Now forcibly take away printer  !!?? 22
  • 23. Attacking Circular Wait Condition  Normally ordered resources  Resource graph 23 (a) (b)
  • 24. Summary of Deadlock Prevention Approaches 24
  • 25. Dealing with Deadlocks – Summary 25 Dealing with Deadlocks Just Ignore Detection & Recovery Preemption Rollback Kill Avoidance Banker’s Algorithm Prevention Spooling Request All Together Take Away Order Numerically

Editor's Notes

  1. Shaded regions are illegal What leads to shaded regions are unsafe