SlideShare une entreprise Scribd logo
1  sur  32
Concurrency: Deadlock and
Starvation
Roadmap
• Principals of Deadlock
– Deadlock prevention
– Deadlock Avoidance
– Deadlock detection
Deadlock
• A set of processes is deadlocked when
each process in the set is blocked awaiting
an event that can only be triggered by
another blocked process in the set
– Typically involves processes competing for
the same set of resources
• No efficient solution
Potential Deadlock
I need
quad A and
B
I need
quad B
and C
I need
quad C
and B
I need
quad D
and A
Actual Deadlock
HALT until
B is free
HALT until
C is free
HALT until
D is free
HALT until
A is free
Resource Categories
Two general categories of resources:
• Reusable
– can be safely used by only one process at a
time and is not depleted by that use.
• Consumable
– one that can be created (produced) and
destroyed (consumed).
Reusable Resources
• Such as:
– Processors, I/O channels, main and
secondary memory, devices, and data
structures such as files, databases, and
semaphores
• Deadlock occurs if each process holds
one resource and requests the other
Example of
Reuse Deadlock
• Consider two processes that compete for
exclusive access to a disk file D and a
tape drive T.
• Deadlock occurs if each process holds
one resource and requests the other.
Reusable Resources
Example
Consider : p0 p1 q0 q1 p2 q2
Example 2:
Memory Request
• Space is available for allocation of
200Kbytes, and the following sequence of
events occur
• Deadlock occurs if both processes
progress to their second request
P1
. . .
. . .
Request 80 Kbytes;
Request 60 Kbytes;
P2
. . .
. . .
Request 70 Kbytes;
Request 80 Kbytes;
Consumable Resources
• Such as Interrupts, signals, messages,
and information in I/O buffers
• Deadlock may occur if a Receive message
is blocking
• May take a rare combination of events to
cause deadlock
Example of Deadlock
• Consider a pair of processes, in which
each process attempts to receive a
message from the other process and then
send a message to the other process
Resource Allocation
Graphs
• Directed graph that depicts a state of the
system of resources and processes
Conditions for
possible Deadlock
• Mutual exclusion
– Only one process may use a resource at a
time
• Hold-and-wait
– A process may hold allocated resources while
awaiting assignment of others
• No pre-emption
– No resource can be forcibly removed form a
process holding it
Actual Deadlock
Requires …
All previous 3 conditions plus:
• 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
Resource Allocation
Graphs of deadlock
Resource Allocation
Graphs
Dealing with Deadlock
• Three general approaches exist for
dealing with deadlock.
– Prevent deadlock
– Avoid deadlock
– Detect Deadlock
Roadmap
• Principals of Deadlock
– Deadlock prevention
– Deadlock Avoidance
– Deadlock detection
Deadlock Prevention
Strategy
• Design a system in such a way that the
possibility of deadlock is excluded.
• Two main methods
– Indirect – prevent all three of the necessary
conditions occurring at once
– Direct – prevent circular waits
Deadlock Prevention
Conditions 1 & 2
• Mutual Exclusion
– Must be supported by the OS
• Hold and Wait
– Require a process request all of its required
resources at one time
• a process may be held up for a long time waiting
• resources allocated to a process may remain
unused for a considerable period
Deadlock Prevention
Conditions 3 & 4
• No Preemption
– Process must release resource and request
again
– OS may preempt a process to require it
releases its resources
• Circular Wait
– Define a linear ordering of resource types
Roadmap
• Principals of Deadlock
– Deadlock prevention
– Deadlock Avoidance
– Deadlock detection
Deadlock Avoidance
• A decision is made dynamically whether
the current resource allocation request
will, if granted, potentially lead to a
deadlock
• Requires knowledge of future process
requests
Two Approaches to
Deadlock Avoidance
• Process Initiation Denial
– Do not start a process if its demands might
lead to deadlock
• Resource Allocation Denial
– Do not grant an incremental resource request
to a process if this allocation might lead to
deadlock
Process
Initiation Denial
• A process is only started if the maximum
claim of all current processes plus those of
the new process can be met.
• Not optimal,
– Assumes the worst: that all processes will
make their maximum claims together.
Resource
Allocation Denial
• Referred to as the banker’s algorithm
– A strategy of resource allocation denial
• Consider a system with fixed number of
resources
– State of the system is the current allocation of
resources to process
– Safe state is where there is at least one
sequence that does not result in deadlock
– Unsafe state is a state that is not safe
Determination of
Safe State
• A system consisting of four processes and
three resources.
• Allocations are made to processors
• Is this a safe state?
Amount of
Existing
Resources
Resources
available
after
allocation
Process i
• Cij - Aij ≤ Vj, for all j
• This is not possible for P1,
– which has only 1 unit of R1 and requires 2
more units of R1, 2 units of R2, and 2 units of
R3.
• If we assign one unit of R3 to process P2,
– Then P2 has its maximum required resources
allocated and can run to completion and
return resources to ‘available’ pool
After P2
runs to completion
• Can any of the remaining processes can
be completed?
Note P2 is
completed
After P1 completes
P3 Completes
Thus, the state defined
originally is a safe
state.

Contenu connexe

Tendances

Thrashing allocation frames.43
Thrashing allocation frames.43Thrashing allocation frames.43
Thrashing allocation frames.43
myrajendra
 
Lecture 8 (software Metrics) Unit 3.pptx
Lecture 8 (software Metrics) Unit 3.pptxLecture 8 (software Metrics) Unit 3.pptx
Lecture 8 (software Metrics) Unit 3.pptx
ironman427662
 
Generic Software Process Models
Generic Software Process ModelsGeneric Software Process Models
Generic Software Process Models
Education Front
 

Tendances (20)

Operating system support in distributed system
Operating system support in distributed systemOperating system support in distributed system
Operating system support in distributed system
 
8 memory management strategies
8 memory management strategies8 memory management strategies
8 memory management strategies
 
Selection of an appropriate project approach
Selection of an appropriate project approachSelection of an appropriate project approach
Selection of an appropriate project approach
 
Resource management
Resource managementResource management
Resource management
 
Distributed Operating System_3
Distributed Operating System_3Distributed Operating System_3
Distributed Operating System_3
 
High Performance & High Throughput Computing - EUDAT Summer School (Giuseppe ...
High Performance & High Throughput Computing - EUDAT Summer School (Giuseppe ...High Performance & High Throughput Computing - EUDAT Summer School (Giuseppe ...
High Performance & High Throughput Computing - EUDAT Summer School (Giuseppe ...
 
Deadlocks in operating system
Deadlocks in operating systemDeadlocks in operating system
Deadlocks in operating system
 
Thrashing allocation frames.43
Thrashing allocation frames.43Thrashing allocation frames.43
Thrashing allocation frames.43
 
Demand paging
Demand pagingDemand paging
Demand paging
 
Rad model
Rad modelRad model
Rad model
 
Distributed file system
Distributed file systemDistributed file system
Distributed file system
 
Resource Management for Computer Operating Systems
Resource Management for Computer Operating SystemsResource Management for Computer Operating Systems
Resource Management for Computer Operating Systems
 
Chapter 01 software engineering pressman
Chapter 01  software engineering pressmanChapter 01  software engineering pressman
Chapter 01 software engineering pressman
 
WEB INTERFACE DESIGN
WEB INTERFACE DESIGNWEB INTERFACE DESIGN
WEB INTERFACE DESIGN
 
Physical and Logical Clocks
Physical and Logical ClocksPhysical and Logical Clocks
Physical and Logical Clocks
 
Client Server Architecture in Software engineering
Client Server Architecture in Software engineeringClient Server Architecture in Software engineering
Client Server Architecture in Software engineering
 
Lecture 8 (software Metrics) Unit 3.pptx
Lecture 8 (software Metrics) Unit 3.pptxLecture 8 (software Metrics) Unit 3.pptx
Lecture 8 (software Metrics) Unit 3.pptx
 
Spm software effort estimation
Spm software effort estimationSpm software effort estimation
Spm software effort estimation
 
Generic Software Process Models
Generic Software Process ModelsGeneric Software Process Models
Generic Software Process Models
 
Parallel computing and its applications
Parallel computing and its applicationsParallel computing and its applications
Parallel computing and its applications
 

Similaire à Deadlocks2

Lecture 6- Deadlocks (1) (1).pptx
Lecture 6- Deadlocks (1) (1).pptxLecture 6- Deadlocks (1) (1).pptx
Lecture 6- Deadlocks (1) (1).pptx
Amanuelmergia
 

Similaire à Deadlocks2 (20)

chapter06-new.pptx
chapter06-new.pptxchapter06-new.pptx
chapter06-new.pptx
 
06-Deadlocks.ppt
06-Deadlocks.ppt06-Deadlocks.ppt
06-Deadlocks.ppt
 
Deadlocks1
Deadlocks1Deadlocks1
Deadlocks1
 
deadlock and starvation resources allocation.pptx
deadlock and starvation resources allocation.pptxdeadlock and starvation resources allocation.pptx
deadlock and starvation resources allocation.pptx
 
Chapter06.ppt
Chapter06.pptChapter06.ppt
Chapter06.ppt
 
Chapter 4
Chapter 4Chapter 4
Chapter 4
 
Deadlocks Part- I.pdf
Deadlocks Part- I.pdfDeadlocks Part- I.pdf
Deadlocks Part- I.pdf
 
3 (2).ppt
3 (2).ppt3 (2).ppt
3 (2).ppt
 
Deadlocks
DeadlocksDeadlocks
Deadlocks
 
3 (1) [Autosaved].ppt
3 (1) [Autosaved].ppt3 (1) [Autosaved].ppt
3 (1) [Autosaved].ppt
 
deadlock.ppt
deadlock.pptdeadlock.ppt
deadlock.ppt
 
OS 7.pptx
OS 7.pptxOS 7.pptx
OS 7.pptx
 
Lecture 6- Deadlocks (1) (1).pptx
Lecture 6- Deadlocks (1) (1).pptxLecture 6- Deadlocks (1) (1).pptx
Lecture 6- Deadlocks (1) (1).pptx
 
7308346-Deadlock.pptx
7308346-Deadlock.pptx7308346-Deadlock.pptx
7308346-Deadlock.pptx
 
Lecture 6- Deadlocks.pptx
Lecture 6- Deadlocks.pptxLecture 6- Deadlocks.pptx
Lecture 6- Deadlocks.pptx
 
OS-Part-06.pdf
OS-Part-06.pdfOS-Part-06.pdf
OS-Part-06.pdf
 
Unit 3 part 2(DEADLOCK)
Unit 3 part 2(DEADLOCK)Unit 3 part 2(DEADLOCK)
Unit 3 part 2(DEADLOCK)
 
The Functions of the Operating System
The Functions of the Operating SystemThe Functions of the Operating System
The Functions of the Operating System
 
Distributed Deadlock Detection.ppt
Distributed Deadlock Detection.pptDistributed Deadlock Detection.ppt
Distributed Deadlock Detection.ppt
 
6. Deadlock_1640227623705.pptx
6. Deadlock_1640227623705.pptx6. Deadlock_1640227623705.pptx
6. Deadlock_1640227623705.pptx
 

Plus de rizwanaabassi

Plus de rizwanaabassi (9)

Memory management1
Memory management1Memory management1
Memory management1
 
Io (2)
Io (2)Io (2)
Io (2)
 
Concurrency
ConcurrencyConcurrency
Concurrency
 
Hci lecture set_03_00
Hci lecture set_03_00Hci lecture set_03_00
Hci lecture set_03_00
 
Hci lecture 01_00
Hci lecture 01_00Hci lecture 01_00
Hci lecture 01_00
 
Oslecture1
Oslecture1Oslecture1
Oslecture1
 
Data com lec1
Data com lec1Data com lec1
Data com lec1
 
Subnetting a class_c_address
Subnetting a class_c_addressSubnetting a class_c_address
Subnetting a class_c_address
 
Pesentation of formal
Pesentation of formalPesentation of formal
Pesentation of formal
 

Dernier

Call Girls In Noida 959961⊹3876 Independent Escort Service Noida
Call Girls In Noida 959961⊹3876 Independent Escort Service NoidaCall Girls In Noida 959961⊹3876 Independent Escort Service Noida
Call Girls In Noida 959961⊹3876 Independent Escort Service Noida
dlhescort
 
Call Girls in Delhi, Escort Service Available 24x7 in Delhi 959961-/-3876
Call Girls in Delhi, Escort Service Available 24x7 in Delhi 959961-/-3876Call Girls in Delhi, Escort Service Available 24x7 in Delhi 959961-/-3876
Call Girls in Delhi, Escort Service Available 24x7 in Delhi 959961-/-3876
dlhescort
 
Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...
Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...
Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...
lizamodels9
 
Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...
Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...
Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...
daisycvs
 
Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...
Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...
Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...
Sheetaleventcompany
 
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
amitlee9823
 
Call Girls In Majnu Ka Tilla 959961~3876 Shot 2000 Night 8000
Call Girls In Majnu Ka Tilla 959961~3876 Shot 2000 Night 8000Call Girls In Majnu Ka Tilla 959961~3876 Shot 2000 Night 8000
Call Girls In Majnu Ka Tilla 959961~3876 Shot 2000 Night 8000
dlhescort
 

Dernier (20)

Cheap Rate Call Girls In Noida Sector 62 Metro 959961乂3876
Cheap Rate Call Girls In Noida Sector 62 Metro 959961乂3876Cheap Rate Call Girls In Noida Sector 62 Metro 959961乂3876
Cheap Rate Call Girls In Noida Sector 62 Metro 959961乂3876
 
Call Girls In Noida 959961⊹3876 Independent Escort Service Noida
Call Girls In Noida 959961⊹3876 Independent Escort Service NoidaCall Girls In Noida 959961⊹3876 Independent Escort Service Noida
Call Girls In Noida 959961⊹3876 Independent Escort Service Noida
 
Cracking the Cultural Competence Code.pptx
Cracking the Cultural Competence Code.pptxCracking the Cultural Competence Code.pptx
Cracking the Cultural Competence Code.pptx
 
BAGALUR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
BAGALUR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRLBAGALUR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
BAGALUR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
 
Dr. Admir Softic_ presentation_Green Club_ENG.pdf
Dr. Admir Softic_ presentation_Green Club_ENG.pdfDr. Admir Softic_ presentation_Green Club_ENG.pdf
Dr. Admir Softic_ presentation_Green Club_ENG.pdf
 
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
 
Call Girls in Delhi, Escort Service Available 24x7 in Delhi 959961-/-3876
Call Girls in Delhi, Escort Service Available 24x7 in Delhi 959961-/-3876Call Girls in Delhi, Escort Service Available 24x7 in Delhi 959961-/-3876
Call Girls in Delhi, Escort Service Available 24x7 in Delhi 959961-/-3876
 
Phases of Negotiation .pptx
 Phases of Negotiation .pptx Phases of Negotiation .pptx
Phases of Negotiation .pptx
 
Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...
Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...
Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...
 
SEO Case Study: How I Increased SEO Traffic & Ranking by 50-60% in 6 Months
SEO Case Study: How I Increased SEO Traffic & Ranking by 50-60%  in 6 MonthsSEO Case Study: How I Increased SEO Traffic & Ranking by 50-60%  in 6 Months
SEO Case Study: How I Increased SEO Traffic & Ranking by 50-60% in 6 Months
 
It will be International Nurses' Day on 12 May
It will be International Nurses' Day on 12 MayIt will be International Nurses' Day on 12 May
It will be International Nurses' Day on 12 May
 
Marel Q1 2024 Investor Presentation from May 8, 2024
Marel Q1 2024 Investor Presentation from May 8, 2024Marel Q1 2024 Investor Presentation from May 8, 2024
Marel Q1 2024 Investor Presentation from May 8, 2024
 
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best Services
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best ServicesMysore Call Girls 8617370543 WhatsApp Number 24x7 Best Services
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best Services
 
Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...
Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...
Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...
 
Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...
Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...
Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...
 
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
 
Falcon's Invoice Discounting: Your Path to Prosperity
Falcon's Invoice Discounting: Your Path to ProsperityFalcon's Invoice Discounting: Your Path to Prosperity
Falcon's Invoice Discounting: Your Path to Prosperity
 
How to Get Started in Social Media for Art League City
How to Get Started in Social Media for Art League CityHow to Get Started in Social Media for Art League City
How to Get Started in Social Media for Art League City
 
Call Girls In Majnu Ka Tilla 959961~3876 Shot 2000 Night 8000
Call Girls In Majnu Ka Tilla 959961~3876 Shot 2000 Night 8000Call Girls In Majnu Ka Tilla 959961~3876 Shot 2000 Night 8000
Call Girls In Majnu Ka Tilla 959961~3876 Shot 2000 Night 8000
 
(Anamika) VIP Call Girls Napur Call Now 8617697112 Napur Escorts 24x7
(Anamika) VIP Call Girls Napur Call Now 8617697112 Napur Escorts 24x7(Anamika) VIP Call Girls Napur Call Now 8617697112 Napur Escorts 24x7
(Anamika) VIP Call Girls Napur Call Now 8617697112 Napur Escorts 24x7
 

Deadlocks2

  • 2. Roadmap • Principals of Deadlock – Deadlock prevention – Deadlock Avoidance – Deadlock detection
  • 3. Deadlock • A set of processes is deadlocked when each process in the set is blocked awaiting an event that can only be triggered by another blocked process in the set – Typically involves processes competing for the same set of resources • No efficient solution
  • 4. Potential Deadlock I need quad A and B I need quad B and C I need quad C and B I need quad D and A
  • 5. Actual Deadlock HALT until B is free HALT until C is free HALT until D is free HALT until A is free
  • 6. Resource Categories Two general categories of resources: • Reusable – can be safely used by only one process at a time and is not depleted by that use. • Consumable – one that can be created (produced) and destroyed (consumed).
  • 7. Reusable Resources • Such as: – Processors, I/O channels, main and secondary memory, devices, and data structures such as files, databases, and semaphores • Deadlock occurs if each process holds one resource and requests the other
  • 8. Example of Reuse Deadlock • Consider two processes that compete for exclusive access to a disk file D and a tape drive T. • Deadlock occurs if each process holds one resource and requests the other.
  • 10. Example 2: Memory Request • Space is available for allocation of 200Kbytes, and the following sequence of events occur • Deadlock occurs if both processes progress to their second request P1 . . . . . . Request 80 Kbytes; Request 60 Kbytes; P2 . . . . . . Request 70 Kbytes; Request 80 Kbytes;
  • 11. Consumable Resources • Such as Interrupts, signals, messages, and information in I/O buffers • Deadlock may occur if a Receive message is blocking • May take a rare combination of events to cause deadlock
  • 12. Example of Deadlock • Consider a pair of processes, in which each process attempts to receive a message from the other process and then send a message to the other process
  • 13. Resource Allocation Graphs • Directed graph that depicts a state of the system of resources and processes
  • 14. Conditions for possible Deadlock • Mutual exclusion – Only one process may use a resource at a time • Hold-and-wait – A process may hold allocated resources while awaiting assignment of others • No pre-emption – No resource can be forcibly removed form a process holding it
  • 15. Actual Deadlock Requires … All previous 3 conditions plus: • 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
  • 18. Dealing with Deadlock • Three general approaches exist for dealing with deadlock. – Prevent deadlock – Avoid deadlock – Detect Deadlock
  • 19. Roadmap • Principals of Deadlock – Deadlock prevention – Deadlock Avoidance – Deadlock detection
  • 20. Deadlock Prevention Strategy • Design a system in such a way that the possibility of deadlock is excluded. • Two main methods – Indirect – prevent all three of the necessary conditions occurring at once – Direct – prevent circular waits
  • 21. Deadlock Prevention Conditions 1 & 2 • Mutual Exclusion – Must be supported by the OS • Hold and Wait – Require a process request all of its required resources at one time • a process may be held up for a long time waiting • resources allocated to a process may remain unused for a considerable period
  • 22. Deadlock Prevention Conditions 3 & 4 • No Preemption – Process must release resource and request again – OS may preempt a process to require it releases its resources • Circular Wait – Define a linear ordering of resource types
  • 23. Roadmap • Principals of Deadlock – Deadlock prevention – Deadlock Avoidance – Deadlock detection
  • 24. Deadlock Avoidance • A decision is made dynamically whether the current resource allocation request will, if granted, potentially lead to a deadlock • Requires knowledge of future process requests
  • 25. Two Approaches to Deadlock Avoidance • Process Initiation Denial – Do not start a process if its demands might lead to deadlock • Resource Allocation Denial – Do not grant an incremental resource request to a process if this allocation might lead to deadlock
  • 26. Process Initiation Denial • A process is only started if the maximum claim of all current processes plus those of the new process can be met. • Not optimal, – Assumes the worst: that all processes will make their maximum claims together.
  • 27. Resource Allocation Denial • Referred to as the banker’s algorithm – A strategy of resource allocation denial • Consider a system with fixed number of resources – State of the system is the current allocation of resources to process – Safe state is where there is at least one sequence that does not result in deadlock – Unsafe state is a state that is not safe
  • 28. Determination of Safe State • A system consisting of four processes and three resources. • Allocations are made to processors • Is this a safe state? Amount of Existing Resources Resources available after allocation
  • 29. Process i • Cij - Aij ≤ Vj, for all j • This is not possible for P1, – which has only 1 unit of R1 and requires 2 more units of R1, 2 units of R2, and 2 units of R3. • If we assign one unit of R3 to process P2, – Then P2 has its maximum required resources allocated and can run to completion and return resources to ‘available’ pool
  • 30. After P2 runs to completion • Can any of the remaining processes can be completed? Note P2 is completed
  • 32. P3 Completes Thus, the state defined originally is a safe state.

Notes de l'éditeur

  1. A set of processes is deadlocked when each process in the set is blocked awaiting an event that can only be triggered by another blocked process in the settypically processes are waiting the freeing up of some requested resource. Deadlock is permanent because none of the events is ever triggered.Unlike other problems in concurrent process management, there is no efficient solution in the general case.
  2. Animated SlideClick 1 Cars approach intersectionThen Cars announce their resource needsAll deadlocks involve conflicting needs for resources by two or more processes. A common example is the traffic deadlock. The typical rule of the road in the United States is that a car at a four-way stop should defer to a car immediately to its right.This rule works if there are only two or three cars at the intersection.If all four cars arrive at about the same time, each will refrain from entering the intersection, this causes a potential deadlock.The deadlock is only potential, not actual, because the necessary resources are available for any of the cars to proceed. If one car eventually does proceed, it can do so.
  3. Animated SlideClick 1 Cars move to deadlockThen Cars announce their resource needBut if all four cars ignore the rules and proceed (cautiously) into the intersection at the same time, then each car seizes one resource (one quadrant) but cannot proceed because the required second resource has already been seized by another car.This is an actual deadlock.
  4. If the amount of memory to be requested is not known ahead of time, it is difficult to deal with this type of deadlock by means of system design constraints. The best way to deal with this particular problem is, in effect, to eliminate the possibility by using virtual memory, which is discussed later (ch 8)
  5. Deadlock occurs if the Receive is blocking (i.e., the receiving process is blocked until the message is received). A design error is the cause of the deadlock. Such errors may be quite subtle and difficult to detect. Furthermore, it may take a rare combination of events to cause the deadlock; thus a program could be in use for a considerable period of time, even years, before the deadlock actually occurs.
  6. A graph edge directed from a process to a resource indicates a resource that has been requested by the process but not yet granted.Within a resource node, a dot is shown for each instance of that resource.A graph edge directed from a reusable resource node dot to a process indicates a request that has been granted
  7. All three must be present for deadlock to occur.
  8. This is actually a potential consequence of the first three.Given that the first three conditions exist, a sequence of events may occur that lead to an unresolvable circular wait. The unresolvable circular wait is in fact the definition of deadlock.The circular wait listed as condition 4 is unresolvable because the first three conditions hold.Thus, the four conditions, taken together, constitute necessary and sufficient conditions for deadlock.
  9. Three general approaches exist for dealing with deadlock.prevent deadlock adopt a policy that eliminates one of the conditions (conditions 1 through 4). avoid deadlock by making the appropriate dynamic choices based on the current state of resource allocation.detect the presence of deadlock (conditions 1 through 4 hold) and take action to recover.We discuss each of these approaches in turn.
  10. Deadlock prevention is strategy simply to design a system in such a way that the possibility of deadlock is excluded.We can view deadlock prevention methods as falling into two classes. indirect method of deadlock prevention is to prevent the occurrence of one of the three necessary conditions listed previously (items 1 through 3). direct method of deadlock prevention is to prevent the occurrence of a circular wait (item 4).We now examine techniques related to each of the fourconditions.
  11. Mutual ExclusionThe first of the four listed conditions cannot be disallowed (in general). If access to a resource requires mutual exclusion, then mutual exclusion must be supported by the OS. Some resources, such as files, may allow multiple accesses for reads but only exclusive access for writes. Even in this case, deadlock can occur if more than one process requires write permission.Hold an WaitCan be prevented by requiring that a process request all of its required resources at one time and blocking the process until all requests can be granted simultaneously. This approach is inefficient in two ways. 1) a process may be held up for a long time waiting for all of its resource requests to be filled, when in fact it could have proceeded with only some of the resources.resources allocated to a process may remain unused for a considerable period, during which time they are denied to other processes. Another problem is that a process may not know in advance all of the resources that it will require.There is also the practical problem created by the use of modular programming or a multithreaded structure for an application. An application would need to be aware of all resources that will be requested at all levels or in all modules to make the simultaneous request.
  12. No Preemptioncan be prevented in several ways. If a process holding certain resources is denied a further request, that process must release its original resources and, if necessary, request them again together with the additional resource.If a process requests a resource that is currently held by another process, the OS may preempt the second process and require it to release its resources.This latter scheme would prevent deadlock only if no two processes possessed the same priority.This approach is practical only with resources whose state can be easily saved and restored later, as is the case with a processor.Circular WaitCan be prevented by defining a linear ordering of resource types. As with hold-and-wait prevention, circular-wait prevention may be inefficient, slowing down processes and denying resource access unnecessarily.
  13. Deadlock avoidance allows the three necessary conditions but makes judicious choices to assure that the deadlock point is never reached. Avoidance allows more concurrency than prevention.With deadlock avoidance, a decision is made dynamically whether the current resource allocation request will, if granted, potentially lead to a deadlock. Deadlock avoidance requires knowledge of future process resource requests.
  14. A process is only started if the maximum claim of all current processes plus those of the new process can be met.This strategy is hardly optimal, because it assumes the worst: that all processes will make their maximum claims together.
  15. Movie button goes to http://gaia.ecs.csus.edu/~zhangd/oscal/Banker/Banker.html
  16. Animation: Callouts explain resource parts of figureThis figure shows the state of a system consisting of four processes and three resources. Total amount of resourcesR1 = 9 R2 = 3 R3 = 6In the current state allocations have been made to the four processes, leaving available1 unit of R2 1 unit of R3Is this a safe state? To answer this question, we ask an intermediate question: Can any of the four processes be run to completion with the resources available? That is, can the difference between the maximum requirement and current allocation for any process be met with the available resources?
  17. In this case, each of the remaining processes could be completed as shown on the next slides
  18. Suppose we choose P1, allocate the required resources, complete P1, and return all of P1’s resources to the available pool.We are left in the state shown in Figure 6.7c on this slide
  19. P3 completes, resulting in the state of Figure 6.7d shown on this slideFinally, we can complete P4. At this point, all of the processes have been run to completion. Thus, the state defined by Figure 6.7a is a safe state.