SlideShare a Scribd company logo
1 of 14
Download to read offline
Deadlock is:
 A set of blocked processes each holding a
resource and waiting to acquire a resource
held by another process in the set.
 Example (hardware resources):
• System has 2 tape drives.
• P1 and P2 each hold one tape drive and each
needs another one.
 Example (“software” resource:):
• semaphores A and B, initialized to 1
P0

1

wait (A);
wait (B);
signal(B);
signal(A);

P1
wait(B)
wait(A)
signal(A)
signal(B)

Chapter 8
The (4) Conditions for Deadlock
There are three policy conditions that must hold for
a deadlock to be possible (the “necessary conditions”):
1. Mutual Exclusion
•

only one process at a time may use a resource

2. Hold-and-Wait
•

a process may hold allocated resources while awaiting
assignment of others

3. No Preemption
•


2

a resource can be released only voluntarily by the
process holding it, after that process has completed its
task

..and a fourth condition which must actually arise
to make a deadlock happen
Chapter 8
The Conditions for Deadlock
 In the presence of these necessary conditions,one
more condition must arise for deadlock to actually
occur:
 4. Circular Wait
• a closed chain of processes exists, such that each
process holds at least one resource needed by the next
process in the chain

3

Chapter 8
The Conditions for Deadlock
 Deadlock occurs if and only if the circular
wait condition is unresolvable
 The circular wait condition is unresolvable
if the first 3 policy conditions hold
 So the 4 conditions taken together
constitute necessary and sufficient
conditions for deadlock
4

Chapter 8
Resource Allocation Graph:
A Cycle But No Deadlock
Multiple
instances
of resources R1
and R2:
P2 and P4 can
complete,
freeing
up resources
for
P1 and P3
5

Chapter 8
Approaches to Handling Deadlocks
 Deadlock Prevention
• disallow 1 of the 3 necessary conditions of
deadlock occurrence, or prevent the circular
wait condition from happening

 Deadlock Avoidance
• do not grant a resource request if this
allocation might lead to deadlock

 Deadlock Detection and Recovery
• grant resource requests when possible, but
periodically check for the presence of deadlock
and then take action to recover from it
6

Chapter 8
Deadlock Avoidance
 We accept the 3 policy conditions but make
judicious choices to assure that the deadlock
point is never reached
 Allows more concurrency than prevention
 Two approaches:
• do not start a process if its total demand might lead to
deadlock: (“Process Initiation Denial”), or
• do not grant an incremental resource request if this
allocation could lead to deadlock: (“Resource Allocation
Denial”)

 In both cases: maximum requirements of each
resource must be stated in advance
7

Chapter 8
Resource Allocation Denial
 A Better Approach:
• Grant incremental resource requests if we can prove that
this leaves the system in a state in which deadlock
cannot occur.
• Based on the concept of a “safe state”

 Banker’s Algorithm:
•
•
•
•
•

8

Tentatively grant each resource request
Analyze resulting system state to see if it is “safe”.
If safe, grant the request
if unsafe refuse the request (undo the tentative grant)
block the requesting process until it is safe to grant it.

Chapter 8
Data Structures for the Banker’s Algorithm
Let n = number of processes,
m = number of resource types
 Available: Vector of length m. If Available [j] = k, there are k
instances of resource type Rj currently available
 Max: n x m matrix. If Max [i,j] = k, then process Pi will request at
most k instances of resource type Rj.
 Alloc: n x m matrix. If Alloc[i,j] = k then Pi is currently allocated
(i.e. holding) k instances of Rj.
 Need: n x m matrix. If Need[i,j] = k, then Pi may need k more
instances of Rj to complete its task.
Safety Algorithm
1. Let Work and Finish be vectors of length m and n,
respectively. Initialize:
Work := Available
Finish [i] == false for i = 1,2, …, n.
2. Find an i such that both:
Finish [i] == false
Needi ≤ Work
If no such i exists, go to step 4.

3. Work := Work + Allocationi
(Resources freed when process completes!)

10

Finish[i] := true
go to step 2.
4. If Finish [i] = true for all i, then the system is in a
safe state.
Chapter 8
Resource-Request Algorithm for Process Pi
Requesti = request vector for Pi .
Requesti [j] = k means process Pi wants k instances of resource
type Rj.
1. If Requesti ≤ Needi go to step 2. Otherwise, error ( process
exceeded its maximum claim).
2. If Requesti ≤ Available, go to step 3. Otherwise Pi must
wait, (resources not available).
3. “Allocate” requested resources to Pi as follows:
Available := Available - Requesti
Alloci := Alloci + Requesti
Needi := Needi – Requesti
If safe ⇒ the resources are allocated to Pi.
If unsafe ⇒ restore the old resource-allocation state and
block Pi

11

Chapter 8
Example of Banker’s Algorithm
5 processes P0 through P4
3 resource types A (10 units), B (5 units), and C (7
units).
Snapshot at time T0:
Allocation Max Available
ABC ABC
ABC
P0 0 1 0
753
332
P1 2 0 0
322
P2 3 0 2
902
P3 2 1 1
222
P4 0 0 2
433
12

Chapter 8
Example (cont)
Need = Max – Allocation
Need
ABC
P0 7 4 3
P1 1 2 2
P2 6 0 0
P3 0 1 1
P4 4 3 1
The system is in a safe state since the sequence < P1, P3,
P4, P2, P0> satisfies safety criteria.
13

Chapter 8
Now P1 requests (1,0,2)
Check that Request ≤ Available
(that is, (1,0,2) ≤ (3,3,2)) ⇒ true.
Allocation
Need
ABC
ABC
P0 0 1 0
743
P1 3 0 2
020
P2 3 0 2
600
P3 2 1 1
011
P4 0 0 2
431

14

Available
ABC
230

Chapter 8

More Related Content

What's hot (20)

Deadlock Avoidance - OS
Deadlock Avoidance - OSDeadlock Avoidance - OS
Deadlock Avoidance - OS
 
Deadlock Avoidance in Operating System
Deadlock Avoidance in Operating SystemDeadlock Avoidance in Operating System
Deadlock Avoidance in Operating System
 
Process synchronization in Operating Systems
Process synchronization in Operating SystemsProcess synchronization in Operating Systems
Process synchronization in Operating Systems
 
Dead Lock in operating system
Dead Lock in operating systemDead Lock in operating system
Dead Lock in operating system
 
Methods for handling deadlock
Methods for handling deadlockMethods for handling deadlock
Methods for handling deadlock
 
Process synchronization
Process synchronizationProcess synchronization
Process synchronization
 
Process state in OS
Process state in OSProcess state in OS
Process state in OS
 
DeadLock in Operating-Systems
DeadLock in Operating-SystemsDeadLock in Operating-Systems
DeadLock in Operating-Systems
 
Deadlock
DeadlockDeadlock
Deadlock
 
Operating System: Deadlock
Operating System: DeadlockOperating System: Deadlock
Operating System: Deadlock
 
Operating system Dead lock
Operating system Dead lockOperating system Dead lock
Operating system Dead lock
 
Process of operating system
Process of operating systemProcess of operating system
Process of operating system
 
Demand paging
Demand pagingDemand paging
Demand paging
 
Disk scheduling
Disk schedulingDisk scheduling
Disk scheduling
 
OS - Deadlock
OS - DeadlockOS - Deadlock
OS - Deadlock
 
Operating System-Process Scheduling
Operating System-Process SchedulingOperating System-Process Scheduling
Operating System-Process Scheduling
 
Bankers algorithm
Bankers algorithmBankers algorithm
Bankers algorithm
 
System calls
System callsSystem calls
System calls
 
OS - Process Concepts
OS - Process ConceptsOS - Process Concepts
OS - Process Concepts
 
Process in operating system
Process in operating systemProcess in operating system
Process in operating system
 

Viewers also liked

Intro to Deadlocks
Intro to DeadlocksIntro to Deadlocks
Intro to Deadlockslionpeal
 
Deadlocks in operating system
Deadlocks in operating systemDeadlocks in operating system
Deadlocks in operating systemMidhun Sankar
 
deadlock prevention
deadlock preventiondeadlock prevention
deadlock preventionNilu Desai
 
Producer consumer
Producer consumerProducer consumer
Producer consumerMohd Tousif
 
24 to 25 deadlockprevention
24 to 25 deadlockprevention24 to 25 deadlockprevention
24 to 25 deadlockpreventionmyrajendra
 
Os presentation process
Os presentation processOs presentation process
Os presentation processNaseer Ahmad
 
Set model and page fault.44
Set model and page fault.44Set model and page fault.44
Set model and page fault.44myrajendra
 
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
 
Ornithopter flying wing mecahnism
Ornithopter flying wing mecahnismOrnithopter flying wing mecahnism
Ornithopter flying wing mecahnismVijay Patil
 
Ornithopter flying wing mecahnism report
Ornithopter flying wing mecahnism reportOrnithopter flying wing mecahnism report
Ornithopter flying wing mecahnism reportVijay Patil
 
Semaphores OS Basics
Semaphores OS BasicsSemaphores OS Basics
Semaphores OS BasicsShijin Raj P
 

Viewers also liked (20)

Intro to Deadlocks
Intro to DeadlocksIntro to Deadlocks
Intro to Deadlocks
 
Deadlocks in operating system
Deadlocks in operating systemDeadlocks in operating system
Deadlocks in operating system
 
deadlock prevention
deadlock preventiondeadlock prevention
deadlock prevention
 
Producer consumer
Producer consumerProducer consumer
Producer consumer
 
Chapter 7 - Deadlocks
Chapter 7 - DeadlocksChapter 7 - Deadlocks
Chapter 7 - Deadlocks
 
O ssvv62015
O ssvv62015O ssvv62015
O ssvv62015
 
24 to 25 deadlockprevention
24 to 25 deadlockprevention24 to 25 deadlockprevention
24 to 25 deadlockprevention
 
Os presentation process
Os presentation processOs presentation process
Os presentation process
 
Ornithopter project
Ornithopter projectOrnithopter project
Ornithopter project
 
Semaphore
SemaphoreSemaphore
Semaphore
 
Set model and page fault.44
Set model and page fault.44Set model and page fault.44
Set model and page fault.44
 
Critical section problem in operating system.
Critical section problem in operating system.Critical section problem in operating system.
Critical section problem in operating system.
 
Mutual exclusion
Mutual exclusionMutual exclusion
Mutual exclusion
 
Ornithopter flying wing mecahnism
Ornithopter flying wing mecahnismOrnithopter flying wing mecahnism
Ornithopter flying wing mecahnism
 
Ornithopter flying wing mecahnism report
Ornithopter flying wing mecahnism reportOrnithopter flying wing mecahnism report
Ornithopter flying wing mecahnism report
 
Deadlock_SVVSDM_DWD
Deadlock_SVVSDM_DWDDeadlock_SVVSDM_DWD
Deadlock_SVVSDM_DWD
 
Semaphores OS Basics
Semaphores OS BasicsSemaphores OS Basics
Semaphores OS Basics
 
Chapter 4
Chapter 4Chapter 4
Chapter 4
 
A petri-net
A petri-netA petri-net
A petri-net
 
Os module 2 d
Os module 2 dOs module 2 d
Os module 2 d
 

Similar to deadlock avoidance

Deadlock avoidance and prevention .. computer networking
Deadlock avoidance and prevention .. computer networkingDeadlock avoidance and prevention .. computer networking
Deadlock avoidance and prevention .. computer networkingTamannaSharma70
 
OSLec14&15(Deadlocksinopratingsystem).pptx
OSLec14&15(Deadlocksinopratingsystem).pptxOSLec14&15(Deadlocksinopratingsystem).pptx
OSLec14&15(Deadlocksinopratingsystem).pptxssusere16bd9
 
14th November - Deadlock Prevention, Avoidance.ppt
14th November - Deadlock Prevention, Avoidance.ppt14th November - Deadlock Prevention, Avoidance.ppt
14th November - Deadlock Prevention, Avoidance.pptUnknown664473
 
Module-2Deadlock.ppt
Module-2Deadlock.pptModule-2Deadlock.ppt
Module-2Deadlock.pptKAnurag2
 
Mch7 deadlock
Mch7 deadlockMch7 deadlock
Mch7 deadlockwahab13
 
Ch8 OS
Ch8 OSCh8 OS
Ch8 OSC.U
 
Deadlock in Real Time operating Systempptx
Deadlock in Real Time operating SystempptxDeadlock in Real Time operating Systempptx
Deadlock in Real Time operating Systempptxssuserca5764
 

Similar to deadlock avoidance (20)

Gp1242 007 oer ppt
Gp1242 007 oer pptGp1242 007 oer ppt
Gp1242 007 oer ppt
 
CH07.pdf
CH07.pdfCH07.pdf
CH07.pdf
 
Deadlock avoidance and prevention .. computer networking
Deadlock avoidance and prevention .. computer networkingDeadlock avoidance and prevention .. computer networking
Deadlock avoidance and prevention .. computer networking
 
DeadlockMar21.ppt
DeadlockMar21.pptDeadlockMar21.ppt
DeadlockMar21.ppt
 
Ice
IceIce
Ice
 
OSLec14&15(Deadlocksinopratingsystem).pptx
OSLec14&15(Deadlocksinopratingsystem).pptxOSLec14&15(Deadlocksinopratingsystem).pptx
OSLec14&15(Deadlocksinopratingsystem).pptx
 
OS_Ch8
OS_Ch8OS_Ch8
OS_Ch8
 
OSCh8
OSCh8OSCh8
OSCh8
 
14th November - Deadlock Prevention, Avoidance.ppt
14th November - Deadlock Prevention, Avoidance.ppt14th November - Deadlock Prevention, Avoidance.ppt
14th November - Deadlock Prevention, Avoidance.ppt
 
Deadlock (1).ppt
Deadlock (1).pptDeadlock (1).ppt
Deadlock (1).ppt
 
Chapter 5(five).pdf
Chapter 5(five).pdfChapter 5(five).pdf
Chapter 5(five).pdf
 
Os5
Os5Os5
Os5
 
Module-2Deadlock.ppt
Module-2Deadlock.pptModule-2Deadlock.ppt
Module-2Deadlock.ppt
 
Mch7 deadlock
Mch7 deadlockMch7 deadlock
Mch7 deadlock
 
Ch8 OS
Ch8 OSCh8 OS
Ch8 OS
 
9 deadlock
9 deadlock9 deadlock
9 deadlock
 
Deadlock
DeadlockDeadlock
Deadlock
 
deadlock part5 unit 2.ppt
deadlock part5 unit 2.pptdeadlock part5 unit 2.ppt
deadlock part5 unit 2.ppt
 
Deadlock in Real Time operating Systempptx
Deadlock in Real Time operating SystempptxDeadlock in Real Time operating Systempptx
Deadlock in Real Time operating Systempptx
 
Operating System
Operating SystemOperating System
Operating System
 

Recently uploaded

Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...Karmanjay Verma
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Mark Simos
 
A Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxA Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxAna-Maria Mihalceanu
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Jeffrey Haguewood
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Accelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with PlatformlessAccelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with PlatformlessWSO2
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
Infrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsInfrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsYoss Cohen
 

Recently uploaded (20)

Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
 
A Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxA Glance At The Java Performance Toolbox
A Glance At The Java Performance Toolbox
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Accelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with PlatformlessAccelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with Platformless
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
Infrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsInfrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platforms
 

deadlock avoidance

  • 1. Deadlock is:  A set of blocked processes each holding a resource and waiting to acquire a resource held by another process in the set.  Example (hardware resources): • System has 2 tape drives. • P1 and P2 each hold one tape drive and each needs another one.  Example (“software” resource:): • semaphores A and B, initialized to 1 P0 1 wait (A); wait (B); signal(B); signal(A); P1 wait(B) wait(A) signal(A) signal(B) Chapter 8
  • 2. The (4) Conditions for Deadlock There are three policy conditions that must hold for a deadlock to be possible (the “necessary conditions”): 1. Mutual Exclusion • only one process at a time may use a resource 2. Hold-and-Wait • a process may hold allocated resources while awaiting assignment of others 3. No Preemption •  2 a resource can be released only voluntarily by the process holding it, after that process has completed its task ..and a fourth condition which must actually arise to make a deadlock happen Chapter 8
  • 3. The Conditions for Deadlock  In the presence of these necessary conditions,one more condition must arise for deadlock to actually occur:  4. Circular Wait • a closed chain of processes exists, such that each process holds at least one resource needed by the next process in the chain 3 Chapter 8
  • 4. The Conditions for Deadlock  Deadlock occurs if and only if the circular wait condition is unresolvable  The circular wait condition is unresolvable if the first 3 policy conditions hold  So the 4 conditions taken together constitute necessary and sufficient conditions for deadlock 4 Chapter 8
  • 5. Resource Allocation Graph: A Cycle But No Deadlock Multiple instances of resources R1 and R2: P2 and P4 can complete, freeing up resources for P1 and P3 5 Chapter 8
  • 6. Approaches to Handling Deadlocks  Deadlock Prevention • disallow 1 of the 3 necessary conditions of deadlock occurrence, or prevent the circular wait condition from happening  Deadlock Avoidance • do not grant a resource request if this allocation might lead to deadlock  Deadlock Detection and Recovery • grant resource requests when possible, but periodically check for the presence of deadlock and then take action to recover from it 6 Chapter 8
  • 7. Deadlock Avoidance  We accept the 3 policy conditions but make judicious choices to assure that the deadlock point is never reached  Allows more concurrency than prevention  Two approaches: • do not start a process if its total demand might lead to deadlock: (“Process Initiation Denial”), or • do not grant an incremental resource request if this allocation could lead to deadlock: (“Resource Allocation Denial”)  In both cases: maximum requirements of each resource must be stated in advance 7 Chapter 8
  • 8. Resource Allocation Denial  A Better Approach: • Grant incremental resource requests if we can prove that this leaves the system in a state in which deadlock cannot occur. • Based on the concept of a “safe state”  Banker’s Algorithm: • • • • • 8 Tentatively grant each resource request Analyze resulting system state to see if it is “safe”. If safe, grant the request if unsafe refuse the request (undo the tentative grant) block the requesting process until it is safe to grant it. Chapter 8
  • 9. Data Structures for the Banker’s Algorithm Let n = number of processes, m = number of resource types  Available: Vector of length m. If Available [j] = k, there are k instances of resource type Rj currently available  Max: n x m matrix. If Max [i,j] = k, then process Pi will request at most k instances of resource type Rj.  Alloc: n x m matrix. If Alloc[i,j] = k then Pi is currently allocated (i.e. holding) k instances of Rj.  Need: n x m matrix. If Need[i,j] = k, then Pi may need k more instances of Rj to complete its task.
  • 10. Safety Algorithm 1. Let Work and Finish be vectors of length m and n, respectively. Initialize: Work := Available Finish [i] == false for i = 1,2, …, n. 2. Find an i such that both: Finish [i] == false Needi ≤ Work If no such i exists, go to step 4. 3. Work := Work + Allocationi (Resources freed when process completes!) 10 Finish[i] := true go to step 2. 4. If Finish [i] = true for all i, then the system is in a safe state. Chapter 8
  • 11. Resource-Request Algorithm for Process Pi Requesti = request vector for Pi . Requesti [j] = k means process Pi wants k instances of resource type Rj. 1. If Requesti ≤ Needi go to step 2. Otherwise, error ( process exceeded its maximum claim). 2. If Requesti ≤ Available, go to step 3. Otherwise Pi must wait, (resources not available). 3. “Allocate” requested resources to Pi as follows: Available := Available - Requesti Alloci := Alloci + Requesti Needi := Needi – Requesti If safe ⇒ the resources are allocated to Pi. If unsafe ⇒ restore the old resource-allocation state and block Pi 11 Chapter 8
  • 12. Example of Banker’s Algorithm 5 processes P0 through P4 3 resource types A (10 units), B (5 units), and C (7 units). Snapshot at time T0: Allocation Max Available ABC ABC ABC P0 0 1 0 753 332 P1 2 0 0 322 P2 3 0 2 902 P3 2 1 1 222 P4 0 0 2 433 12 Chapter 8
  • 13. Example (cont) Need = Max – Allocation Need ABC P0 7 4 3 P1 1 2 2 P2 6 0 0 P3 0 1 1 P4 4 3 1 The system is in a safe state since the sequence < P1, P3, P4, P2, P0> satisfies safety criteria. 13 Chapter 8
  • 14. Now P1 requests (1,0,2) Check that Request ≤ Available (that is, (1,0,2) ≤ (3,3,2)) ⇒ true. Allocation Need ABC ABC P0 0 1 0 743 P1 3 0 2 020 P2 3 0 2 600 P3 2 1 1 011 P4 0 0 2 431 14 Available ABC 230 Chapter 8