SlideShare a Scribd company logo
1 of 25
MS.A.Dhivya M.Sc., M.Phil.,
Assistant Professor
 Process is blocked on resource that will never
be released.
 Deadlocks waste resources
 Deadlocks are rare:
 Many systems ignore them
 Resolved by explicit user intervention
 Critical in many real-time applications
 May cause damage, endanger life
 Reusable Resources
 Number of units is “constant”
 Unit is either free or allocated; no sharing
 Process requests, acquires, releases units
Examples: memory, devices, files, tables
 Consumable Resources
 Number of units varies at runtime
 Process may create new units
 Process may consume units
Examples: messages, signals
p1: ... p2: ...
open(f1,w); open(f2,w);
open(f2,w); open(f1,w);
... ...
 Deadlock when executed concurrently
p1: if (C) send(p2,m); p2: ...
while(1){... while(1){...
recv(p2,m); recv(p1,m);
send(p2,m); send(p1,m);
... } ... }
 Deadlock when C not true
 Deadlock: Processes are blocked
 Livelock: Processes run but make no progress
 Both deadlock and livelock lead to starvation
 Starvation may have other causes
 ML scheduling where one queue is never empty
 Memory requests: unbounded stream of 100MB
requests may starve a 200MB request
1. Detection and Recovery
 Allow deadlock to happen and eliminate it
2. Avoidance (dynamic)
 Runtime checks disallow allocations
that might lead to deadlocks
3. Prevention (static)
Restrict type of request and acquisition
to make deadlock impossible
 Assumptions:
 When a process requests a resource, either the
request is fully granted or the process blocks
 No partial allocation
 A process can only release resources that it holds
 Resource graph:
 Vertices are processes, resources, resource units
 Edges (directed) represent requests and allocations
of resources
Resource graph:
Process = Circle
Resource = Rectangle with small circles for each unit
Request = Edge from process to resource class
Allocation = Edge from resource unit to process
Request: Create new request edge piRj
 pi has no outstanding requests
 number of edges between pi and Rj cannot
exceed total units of Rj
Acquisition: Reverse request edge to piRj
 All requests of pi are satisfiable
 pi has no outstanding requests
Release: Remove edge piRj
 A process is blocked in state S if it cannot
request, acquire, or release any resource.
 A process is deadlocked in state S if it is
currently blocked now and remains blocked
in all states reachable from state S
 A state is a deadlock state if it contains a
deadlocked process.
 State S is a safe state if no deadlock state can
be reached from S by any sequence of
request, acquire, release.
2 processes p1 , p2; 2 resources R1, R2,
 p1 and p2 both need R1 and R2
 p1 requests R1 before R2 and releases R2 before R1
 p2 requests R2 before R1 and releases R1 before R2
 p1 and p2 both need
R1 and R2
 p1
requests R1 before
R2
and
releases R2 before
R1
 p2
requests R2 before
R1
and
releases R1 before
R2
 Graph Reduction: Repeat the following
1. Select unblocked process p
2. Remove p and all request and allocation edges
 Deadlock  Graph not completely reducible.
 All reduction sequences lead to the same
result.
 Testing for whether a specific process p is
deadlocked:
 Reduce until p is removed or graph irreducible
 Continuous detection:
1. Current state not deadlocked
2. Next state T deadlocked only if:
a. Operation was a request by p and
b. p is deadlocked in T
3. Try to reduce T by p
 Immediate allocations
 All satisfiable requests granted immediately
 Expedient state: state with no satisfiable request
edges
 If all requests are granted immediately, all states
are expedient.
Not expedient (p1->R1)
 Immediate allocations, continued.
 Knot : A set K of nodes such that
 Every node in K reachable from any other node in K
 No outgoing edges from any node in K
 Knot in expedient state  Deadlock :
 Reason:
 All processes in K must have outstanding requests
 Expedient state means requests not satisfiable
(Remove R2->p1: knot R2,p3,R3,p5)
(Reverse edge p1->R1): expedient state
 For single-unit resources, cycle  deadlock
 Every p must have a request edge to R
 Every R must have an allocation edge to p
 R is not available and thus p is blocked
 Wait-For Graph (wfg): Show only processes
 Replace p1R p2 by p1  p2 : p1 waits for p2
 Central Coordinator
(CC)
 Each machine maintains
a local wfg
 Changes reported to CC
 CC constructs and
analyzes global wfg
 Problems
 Coordinator is a
performance bottleneck
 Communication delays
may cause phantom
deadlocks
 Distributed Approach
 Detect cycles using probes.
 If process pi blocked on pj , it launches probe pi  pj
 pj sends probe pi  pj  pk along all request edges, etc.
 When probe returns to pi, cycle is detected
 Process termination
 Kill all processes involved in deadlock; or
 Kill one at a time. In what order?
 By priority: consistent with scheduling
 By cost of restart: length of recomputation
 By impact on other processes: CS, producer/consumer
 Resource preemption
 Direct: Temporarily remove resource (e.g., Memory)
 Indirect: Rollback to earlier “checkpoint”
 Maximum Claim Graph
 Process indicates
maximum resources
needed
 Potential request edge
piRj (dashed)
 May turn into
real request edge
 Theorem: Prevent acquisitions that do not produce a
completely reducible graph
 All state are safe.
 Banker’s algorithm (Dijkstra):
 Given a satisfiable request, pR, temporarily grant request,
changing pR to Rp
 Try to reduce new claim graph, treating claim edges as
actual requests.
 If new claim graph is completely reducible proceed. If not,
reverse temporary acquisition Rp back to pR
 Analogy with banking: resources correspond to
currencies, allocations correspond to loans,
maximum claims correspond to credit limits
 Claim graph (a). Which
requests for R1 can
safely be granted?
 If p1’s request is
granted, resulting claim
graph (b) is reducible
(p1,p3,p2).
 If p2’s request is
granted, resulting claim
graph (c) is not
reducible.
 Exercise: what about
p3’s request?
 Deadlock requires the following conditions:
 Mutual exclusion:
 Resources not sharable
 Hold and wait:
 Process must be holding one resource
while requesting another
 Circular wait:
 At least 2 processes must be
blocked on each other
 Eliminate mutual exclusion:
 Not possible in most cases
 Spooling makes I/O devices sharable
 Eliminate hold-and-wait
 Request all resources at once
 Release all resources before a new request
 Release all resources if current request blocks
 Eliminate circular wait
 Order all resources: SEQ(Ri)  SEQ(Rj)
 Process must request in ascending order

More Related Content

What's hot

INTER PROCESS COMMUNICATION (IPC).pptx
INTER PROCESS COMMUNICATION (IPC).pptxINTER PROCESS COMMUNICATION (IPC).pptx
INTER PROCESS COMMUNICATION (IPC).pptxLECO9
 
Control Strategies in AI
Control Strategies in AIControl Strategies in AI
Control Strategies in AIAmey Kerkar
 
Process Synchronization
Process SynchronizationProcess Synchronization
Process SynchronizationSonali Chauhan
 
Critical section problem in operating system.
Critical section problem in operating system.Critical section problem in operating system.
Critical section problem in operating system.MOHIT DADU
 
Multi processor scheduling
Multi  processor schedulingMulti  processor scheduling
Multi processor schedulingShashank Kapoor
 
Communication primitives
Communication primitivesCommunication primitives
Communication primitivesStudent
 
Process synchronization in Operating Systems
Process synchronization in Operating SystemsProcess synchronization in Operating Systems
Process synchronization in Operating SystemsRitu Ranjan Shrivastwa
 
deadlock avoidance
deadlock avoidancedeadlock avoidance
deadlock avoidancewahab13
 
Lecture 14 run time environment
Lecture 14 run time environmentLecture 14 run time environment
Lecture 14 run time environmentIffat Anjum
 
Operating system Dead lock
Operating system Dead lockOperating system Dead lock
Operating system Dead lockKaram Munir Butt
 
Distributed system lamport's and vector algorithm
Distributed system lamport's and vector algorithmDistributed system lamport's and vector algorithm
Distributed system lamport's and vector algorithmpinki soni
 
File replication
File replicationFile replication
File replicationKlawal13
 

What's hot (20)

INTER PROCESS COMMUNICATION (IPC).pptx
INTER PROCESS COMMUNICATION (IPC).pptxINTER PROCESS COMMUNICATION (IPC).pptx
INTER PROCESS COMMUNICATION (IPC).pptx
 
Deadlock
DeadlockDeadlock
Deadlock
 
Control Strategies in AI
Control Strategies in AIControl Strategies in AI
Control Strategies in AI
 
CPU Scheduling Algorithms
CPU Scheduling AlgorithmsCPU Scheduling Algorithms
CPU Scheduling Algorithms
 
Process Synchronization
Process SynchronizationProcess Synchronization
Process Synchronization
 
Operating System: Deadlock
Operating System: DeadlockOperating System: Deadlock
Operating System: Deadlock
 
Critical section problem in operating system.
Critical section problem in operating system.Critical section problem in operating system.
Critical section problem in operating system.
 
Multi processor scheduling
Multi  processor schedulingMulti  processor scheduling
Multi processor scheduling
 
Communication primitives
Communication primitivesCommunication primitives
Communication primitives
 
Memory management
Memory managementMemory management
Memory management
 
Process synchronization in Operating Systems
Process synchronization in Operating SystemsProcess synchronization in Operating Systems
Process synchronization in Operating Systems
 
Naming in Distributed System
Naming in Distributed SystemNaming in Distributed System
Naming in Distributed System
 
Chapter 7 - Deadlocks
Chapter 7 - DeadlocksChapter 7 - Deadlocks
Chapter 7 - Deadlocks
 
deadlock avoidance
deadlock avoidancedeadlock avoidance
deadlock avoidance
 
Lecture 14 run time environment
Lecture 14 run time environmentLecture 14 run time environment
Lecture 14 run time environment
 
Operating system Dead lock
Operating system Dead lockOperating system Dead lock
Operating system Dead lock
 
OS - Deadlock
OS - DeadlockOS - Deadlock
OS - Deadlock
 
Distributed system lamport's and vector algorithm
Distributed system lamport's and vector algorithmDistributed system lamport's and vector algorithm
Distributed system lamport's and vector algorithm
 
Concurrency
ConcurrencyConcurrency
Concurrency
 
File replication
File replicationFile replication
File replication
 

Similar to Deadlock prevention techniques in distributed systems

Similar to Deadlock prevention techniques in distributed systems (20)

Os6 2
Os6 2Os6 2
Os6 2
 
Os6
Os6Os6
Os6
 
Deadlock Detection Algorithm
Deadlock Detection AlgorithmDeadlock Detection Algorithm
Deadlock Detection Algorithm
 
Sucet os module_3_notes
Sucet os module_3_notesSucet os module_3_notes
Sucet os module_3_notes
 
Bankers
BankersBankers
Bankers
 
7308346-Deadlock.pptx
7308346-Deadlock.pptx7308346-Deadlock.pptx
7308346-Deadlock.pptx
 
CH07.pdf
CH07.pdfCH07.pdf
CH07.pdf
 
CSS430_Deadlock.pptx
CSS430_Deadlock.pptxCSS430_Deadlock.pptx
CSS430_Deadlock.pptx
 
Deadlocks
Deadlocks Deadlocks
Deadlocks
 
Operating System
Operating SystemOperating System
Operating System
 
Os unit 4
Os unit 4Os unit 4
Os unit 4
 
Lecture5
Lecture5Lecture5
Lecture5
 
Mch7 deadlock
Mch7 deadlockMch7 deadlock
Mch7 deadlock
 
Module 3 Deadlocks.pptx
Module 3 Deadlocks.pptxModule 3 Deadlocks.pptx
Module 3 Deadlocks.pptx
 
Dead Lock In Operating Systems
Dead Lock In Operating SystemsDead Lock In Operating Systems
Dead Lock In Operating Systems
 
OS Module-3 (2).pptx
OS Module-3 (2).pptxOS Module-3 (2).pptx
OS Module-3 (2).pptx
 
Dead lock
Dead lockDead lock
Dead lock
 
DeadlockMar21.ppt
DeadlockMar21.pptDeadlockMar21.ppt
DeadlockMar21.ppt
 
Deadlock
DeadlockDeadlock
Deadlock
 
Deadlock
DeadlockDeadlock
Deadlock
 

More from DHIVYADEVAKI

Computer Networks - DNS
Computer Networks - DNSComputer Networks - DNS
Computer Networks - DNSDHIVYADEVAKI
 
Error detection methods-computer networks
Error detection methods-computer networksError detection methods-computer networks
Error detection methods-computer networksDHIVYADEVAKI
 
Introduction basic schema and SQL QUERIES
Introduction basic schema and SQL QUERIESIntroduction basic schema and SQL QUERIES
Introduction basic schema and SQL QUERIESDHIVYADEVAKI
 
Image compression in digital image processing
Image compression in digital image processingImage compression in digital image processing
Image compression in digital image processingDHIVYADEVAKI
 
Image segmentation in Digital Image Processing
Image segmentation in Digital Image ProcessingImage segmentation in Digital Image Processing
Image segmentation in Digital Image ProcessingDHIVYADEVAKI
 
Data preprocessing in Data Mining
Data preprocessing in Data MiningData preprocessing in Data Mining
Data preprocessing in Data MiningDHIVYADEVAKI
 
Apriori algorithm
Apriori algorithm Apriori algorithm
Apriori algorithm DHIVYADEVAKI
 
Types of Load distributing algorithm in Distributed System
Types of Load distributing algorithm in Distributed SystemTypes of Load distributing algorithm in Distributed System
Types of Load distributing algorithm in Distributed SystemDHIVYADEVAKI
 

More from DHIVYADEVAKI (9)

Computer Networks - DNS
Computer Networks - DNSComputer Networks - DNS
Computer Networks - DNS
 
Error detection methods-computer networks
Error detection methods-computer networksError detection methods-computer networks
Error detection methods-computer networks
 
Introduction basic schema and SQL QUERIES
Introduction basic schema and SQL QUERIESIntroduction basic schema and SQL QUERIES
Introduction basic schema and SQL QUERIES
 
Image compression in digital image processing
Image compression in digital image processingImage compression in digital image processing
Image compression in digital image processing
 
Image segmentation in Digital Image Processing
Image segmentation in Digital Image ProcessingImage segmentation in Digital Image Processing
Image segmentation in Digital Image Processing
 
R graphics
R graphicsR graphics
R graphics
 
Data preprocessing in Data Mining
Data preprocessing in Data MiningData preprocessing in Data Mining
Data preprocessing in Data Mining
 
Apriori algorithm
Apriori algorithm Apriori algorithm
Apriori algorithm
 
Types of Load distributing algorithm in Distributed System
Types of Load distributing algorithm in Distributed SystemTypes of Load distributing algorithm in Distributed System
Types of Load distributing algorithm in Distributed System
 

Recently uploaded

Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 

Recently uploaded (20)

Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 

Deadlock prevention techniques in distributed systems

  • 2.  Process is blocked on resource that will never be released.  Deadlocks waste resources  Deadlocks are rare:  Many systems ignore them  Resolved by explicit user intervention  Critical in many real-time applications  May cause damage, endanger life
  • 3.  Reusable Resources  Number of units is “constant”  Unit is either free or allocated; no sharing  Process requests, acquires, releases units Examples: memory, devices, files, tables  Consumable Resources  Number of units varies at runtime  Process may create new units  Process may consume units Examples: messages, signals
  • 4. p1: ... p2: ... open(f1,w); open(f2,w); open(f2,w); open(f1,w); ... ...  Deadlock when executed concurrently p1: if (C) send(p2,m); p2: ... while(1){... while(1){... recv(p2,m); recv(p1,m); send(p2,m); send(p1,m); ... } ... }  Deadlock when C not true
  • 5.  Deadlock: Processes are blocked  Livelock: Processes run but make no progress  Both deadlock and livelock lead to starvation  Starvation may have other causes  ML scheduling where one queue is never empty  Memory requests: unbounded stream of 100MB requests may starve a 200MB request
  • 6. 1. Detection and Recovery  Allow deadlock to happen and eliminate it 2. Avoidance (dynamic)  Runtime checks disallow allocations that might lead to deadlocks 3. Prevention (static) Restrict type of request and acquisition to make deadlock impossible
  • 7.  Assumptions:  When a process requests a resource, either the request is fully granted or the process blocks  No partial allocation  A process can only release resources that it holds  Resource graph:  Vertices are processes, resources, resource units  Edges (directed) represent requests and allocations of resources
  • 8. Resource graph: Process = Circle Resource = Rectangle with small circles for each unit Request = Edge from process to resource class Allocation = Edge from resource unit to process
  • 9. Request: Create new request edge piRj  pi has no outstanding requests  number of edges between pi and Rj cannot exceed total units of Rj Acquisition: Reverse request edge to piRj  All requests of pi are satisfiable  pi has no outstanding requests Release: Remove edge piRj
  • 10.  A process is blocked in state S if it cannot request, acquire, or release any resource.  A process is deadlocked in state S if it is currently blocked now and remains blocked in all states reachable from state S  A state is a deadlock state if it contains a deadlocked process.  State S is a safe state if no deadlock state can be reached from S by any sequence of request, acquire, release.
  • 11. 2 processes p1 , p2; 2 resources R1, R2,  p1 and p2 both need R1 and R2  p1 requests R1 before R2 and releases R2 before R1  p2 requests R2 before R1 and releases R1 before R2
  • 12.  p1 and p2 both need R1 and R2  p1 requests R1 before R2 and releases R2 before R1  p2 requests R2 before R1 and releases R1 before R2
  • 13.  Graph Reduction: Repeat the following 1. Select unblocked process p 2. Remove p and all request and allocation edges  Deadlock  Graph not completely reducible.  All reduction sequences lead to the same result.
  • 14.  Testing for whether a specific process p is deadlocked:  Reduce until p is removed or graph irreducible  Continuous detection: 1. Current state not deadlocked 2. Next state T deadlocked only if: a. Operation was a request by p and b. p is deadlocked in T 3. Try to reduce T by p
  • 15.  Immediate allocations  All satisfiable requests granted immediately  Expedient state: state with no satisfiable request edges  If all requests are granted immediately, all states are expedient. Not expedient (p1->R1)
  • 16.  Immediate allocations, continued.  Knot : A set K of nodes such that  Every node in K reachable from any other node in K  No outgoing edges from any node in K  Knot in expedient state  Deadlock :  Reason:  All processes in K must have outstanding requests  Expedient state means requests not satisfiable (Remove R2->p1: knot R2,p3,R3,p5) (Reverse edge p1->R1): expedient state
  • 17.  For single-unit resources, cycle  deadlock  Every p must have a request edge to R  Every R must have an allocation edge to p  R is not available and thus p is blocked  Wait-For Graph (wfg): Show only processes  Replace p1R p2 by p1  p2 : p1 waits for p2
  • 18.  Central Coordinator (CC)  Each machine maintains a local wfg  Changes reported to CC  CC constructs and analyzes global wfg  Problems  Coordinator is a performance bottleneck  Communication delays may cause phantom deadlocks
  • 19.  Distributed Approach  Detect cycles using probes.  If process pi blocked on pj , it launches probe pi  pj  pj sends probe pi  pj  pk along all request edges, etc.  When probe returns to pi, cycle is detected
  • 20.  Process termination  Kill all processes involved in deadlock; or  Kill one at a time. In what order?  By priority: consistent with scheduling  By cost of restart: length of recomputation  By impact on other processes: CS, producer/consumer  Resource preemption  Direct: Temporarily remove resource (e.g., Memory)  Indirect: Rollback to earlier “checkpoint”
  • 21.  Maximum Claim Graph  Process indicates maximum resources needed  Potential request edge piRj (dashed)  May turn into real request edge
  • 22.  Theorem: Prevent acquisitions that do not produce a completely reducible graph  All state are safe.  Banker’s algorithm (Dijkstra):  Given a satisfiable request, pR, temporarily grant request, changing pR to Rp  Try to reduce new claim graph, treating claim edges as actual requests.  If new claim graph is completely reducible proceed. If not, reverse temporary acquisition Rp back to pR  Analogy with banking: resources correspond to currencies, allocations correspond to loans, maximum claims correspond to credit limits
  • 23.  Claim graph (a). Which requests for R1 can safely be granted?  If p1’s request is granted, resulting claim graph (b) is reducible (p1,p3,p2).  If p2’s request is granted, resulting claim graph (c) is not reducible.  Exercise: what about p3’s request?
  • 24.  Deadlock requires the following conditions:  Mutual exclusion:  Resources not sharable  Hold and wait:  Process must be holding one resource while requesting another  Circular wait:  At least 2 processes must be blocked on each other
  • 25.  Eliminate mutual exclusion:  Not possible in most cases  Spooling makes I/O devices sharable  Eliminate hold-and-wait  Request all resources at once  Release all resources before a new request  Release all resources if current request blocks  Eliminate circular wait  Order all resources: SEQ(Ri)  SEQ(Rj)  Process must request in ascending order