2
Most read
3
Most read
Methods for Handling Deadlocks
Generally speaking, we can deal with the deadlock problem in one of three ways:
 We can use a protocol to prevent or avoid deadlocks, ensuring that the system will never
enter a deadlocked state.
 We can allow the system to enter a deadlocked state, detect it, and recover.
 We can ignore the problem altogether and pretend that deadlocks never occur in the system.
Deadlock prevention provides a set of methods to ensure that at least one of the necessary
conditions cannot hold. These methods prevent deadlocks by constraining how requests for
resources can be made.
Deadlock avoidance requires that the operating system be given additional information in
advance concerning which resources a process will request and use during its lifetime. With this
additional knowledge, the operating system can decide for each request whether or not the process
should wait. To decide whether the current request can be satisfied or must be delayed, the system
must consider the resources currently available, the resources currently allocated to each process,
and the future requests and releases of each process.
Deadlock Prevention
We elaborate on this approach by examining each of the four necessary conditions separately
Mutual Exclusion The mutual exclusion condition must hold. That is, at least one resource must
be nonsharable. Sharable resources, in contrast, do not require mutually exclusive access and thus
cannot be involved in a deadlock.
Hold and Wait To ensure that the hold-and-wait condition never occurs in the system, we must
guarantee that, whenever a process requests a resource, it does not hold any other resources.
No Preemption The third necessary condition for deadlocks is that there be no preemption of
resources that have already been allocated. To ensure that this condition does not hold, we can use
the following protocol. If a process is holding some resources and requests another resource that
cannot be immediately allocated to it (that is, the process must wait), then all resources the process
is currently holding are preempted. In otherwords, these resources are implicitly released. The
preempted resources are added to the list of resources for which the process is waiting.
Circular wait To avoid circular wait, resources may be ordered and we can ensure that each
process can request resources only in an increasing order of these numbers.
Deadlock Avoidance
Safe State
A state is safe if the system can allocate resources to each process (up to its maximum) in some
order and still avoid a deadlock. More formally, a system is in a safe state only if there exists a
safe sequence. A sequence of processes <P1, P2, ..., Pn> is a safe sequence for the current
allocation state if, for each Pi , the resource requests that Pi can still make can be satisfied by the
currently available resources plus the resources held by all Pj, with j < i. In this situation, if the
resources that Pi needs are not immediately available, then Pi can wait until all Pj have finished.
When they have finished, Pi can obtain all of its needed resources, complete its designated task,
return its allocated resources, and terminate. When Pi terminates, Pi+1 can obtain its needed
resources, and so on. If no such sequence exists, then the system state is said to be unsafe. A safe
state is not a deadlocked state. Conversely, a deadlocked state is an unsafe state. Not all unsafe
states are deadlocks, however (Figure 7.6). An unsafe state may lead to a deadlock.
Resource-Allocation-Graph Algorithm
In addition to the request and assignment edges already described, we introduce a new type of
edge, called a claim edge. A claim edge Pi → Rj indicates that process Pi may request resource
Rj at some time in the future. This edge resembles a request edge in direction but is represented in
the graph by a dashed line. When process Pi requests resource Rj , the claim edge Pi → Rj is
converted to a request edge. Similarly, when a resource Rj is released by Pi , the assignment edge
Rj → Pi is reconverted to a claim edge Pi → Rj .
Now suppose that process Pi requests resource Rj. The request can be granted only if converting
the request edge Pi → Rj to an assignment edge Rj → Pi does not result in the formation of a cycle
in the resource-allocation graph. If no cycle exists, then the allocation of the resource will leave
the system in a safe state. If a cycle is found, then the allocation will put the system in an unsafe
state.
To illustrate this algorithm, we consider the resource-allocation graph of Figure 7.7. Suppose that
P2 requests R2. Although R2 is currently free, we cannot allocate it to P2, since this action will
create a cycle in the graph (Figure 7.8). A cycle, as mentioned, indicates that the system is in an
unsafe state. If P1 requests R2, and P2 requests R1, then a deadlock will occur.

More Related Content

PPTX
Concurrency Control in Distributed Database.
PDF
Deadlock
PPT
Deadlock
PPT
Priority scheduling algorithms
PPTX
Deadlock ppt
PPT
deadlock avoidance
PPT
Thrashing allocation frames.43
PPTX
Multi processor scheduling
Concurrency Control in Distributed Database.
Deadlock
Deadlock
Priority scheduling algorithms
Deadlock ppt
deadlock avoidance
Thrashing allocation frames.43
Multi processor scheduling

What's hot (20)

PDF
Memory management
PPT
Distributed Deadlock Detection.ppt
PPTX
Process management os concept
PPTX
INTER PROCESS COMMUNICATION (IPC).pptx
PPTX
Deadlock dbms
PPTX
Cpu scheduling in operating System.
PPTX
Deadlock Prevention
PPT
Concurrent transactions
PDF
Semaphores
PPT
Chapter 6 - Process Synchronization
PPT
Contiguous Memory Allocation.ppt
PPTX
Process synchronization in Operating Systems
PPTX
Code Optimization
PPT
Memory Management in OS
PPTX
All pair shortest path
PPT
Chapter 12 - Mass Storage Systems
PPTX
Distributed operating system
PPTX
SCHEDULING ALGORITHMS
Memory management
Distributed Deadlock Detection.ppt
Process management os concept
INTER PROCESS COMMUNICATION (IPC).pptx
Deadlock dbms
Cpu scheduling in operating System.
Deadlock Prevention
Concurrent transactions
Semaphores
Chapter 6 - Process Synchronization
Contiguous Memory Allocation.ppt
Process synchronization in Operating Systems
Code Optimization
Memory Management in OS
All pair shortest path
Chapter 12 - Mass Storage Systems
Distributed operating system
SCHEDULING ALGORITHMS
Ad

Similar to Methods for handling deadlocks (20)

PPTX
6. Deadlock_1640227623705.pptx
PPT
FP 202 Chapter 2 - Part 3
PDF
Os unit 4
PDF
Deadlock in Distributed Systems
PPT
Deadlock
PPT
Ch07 deadlocks
PDF
deadlock.pdfdkfglknalkdnglqgjlejgooooo;o
PDF
deadlocks for Engenerring for he purpose
PPTX
osvzjsjjdndnnssnnsnsndndndnndeadlock.pptx
PPT
Mch7 deadlock
PPT
Chapter 7 - Deadlocks
PDF
Deadlocks
PPTX
Module 3 Deadlocks.pptx
PPTX
Algorithm 4Chapter Four- Deadlock (5).pptx
PPTX
Gp1242 007 oer ppt
PPT
Deadlock.ppt
PPTX
OS Module-3 (2).pptx
PDF
Deadlocks
PPT
6. Deadlock_1640227623705.pptx
FP 202 Chapter 2 - Part 3
Os unit 4
Deadlock in Distributed Systems
Deadlock
Ch07 deadlocks
deadlock.pdfdkfglknalkdnglqgjlejgooooo;o
deadlocks for Engenerring for he purpose
osvzjsjjdndnnssnnsnsndndndnndeadlock.pptx
Mch7 deadlock
Chapter 7 - Deadlocks
Deadlocks
Module 3 Deadlocks.pptx
Algorithm 4Chapter Four- Deadlock (5).pptx
Gp1242 007 oer ppt
Deadlock.ppt
OS Module-3 (2).pptx
Deadlocks
Ad

More from A. S. M. Shafi (20)

DOCX
Data Warehouse Schema (Star, Snowflake).docx
PDF
Correlation Analysis in Machine Learning.pdf
PDF
Naive Bayes and Decision Tree Algorithm.pdf
PDF
Frequent Pattern Growth Mining Algorithm.pdf
PDF
Direct Hashing and Pruning Algorithm in Data MIning.pdf
PDF
Association Rule Mining with Apriori Algorithm.pdf
PDF
HITS Algorithm in Data and Web MIning.pdf
PDF
Page Rank Algorithm in Data Mining and Web Application.pdf
PDF
K Nearest Neighbor Classifier in Machine Learning.pdf
PDF
K Means Clustering Algorithm in Machine Learning.pdf
PDF
2D Transformation in Computer Graphics
PDF
3D Transformation in Computer Graphics
PDF
Projection
PDF
2D Transformation
PDF
Line drawing algorithm
PDF
Fragmentation
PDF
File organization
PDF
Bankers algorithm
PDF
RR and priority scheduling
PDF
Fcfs and sjf
Data Warehouse Schema (Star, Snowflake).docx
Correlation Analysis in Machine Learning.pdf
Naive Bayes and Decision Tree Algorithm.pdf
Frequent Pattern Growth Mining Algorithm.pdf
Direct Hashing and Pruning Algorithm in Data MIning.pdf
Association Rule Mining with Apriori Algorithm.pdf
HITS Algorithm in Data and Web MIning.pdf
Page Rank Algorithm in Data Mining and Web Application.pdf
K Nearest Neighbor Classifier in Machine Learning.pdf
K Means Clustering Algorithm in Machine Learning.pdf
2D Transformation in Computer Graphics
3D Transformation in Computer Graphics
Projection
2D Transformation
Line drawing algorithm
Fragmentation
File organization
Bankers algorithm
RR and priority scheduling
Fcfs and sjf

Recently uploaded (20)

PPT
hemostasis and its significance, physiology
PDF
Hospital Case Study .architecture design
PPTX
principlesofmanagementsem1slides-131211060335-phpapp01 (1).ppt
PPT
Acidosis in Dairy Herds: Causes, Signs, Management, Prevention and Treatment
PDF
FYJC - Chemistry textbook - standard 11.
PPTX
Cite It Right: A Compact Illustration of APA 7th Edition.pptx
PPTX
MMW-CHAPTER-1-final.pptx major Elementary Education
PPTX
Designing Adaptive Learning Paths in Virtual Learning Environments
PDF
faiz-khans about Radiotherapy Physics-02.pdf
PPTX
4. Diagnosis and treatment planning in RPD.pptx
PDF
Chevening Scholarship Application and Interview Preparation Guide
PDF
CHALLENGES FACED BY TEACHERS WHEN TEACHING LEARNERS WITH DEVELOPMENTAL DISABI...
PPTX
Key-Features-of-the-SHS-Program-v4-Slides (3) PPT2.pptx
PPTX
PLASMA AND ITS CONSTITUENTS 123.pptx
PPT
hsl powerpoint resource goyloveh feb 07.ppt
PPTX
pharmaceutics-1unit-1-221214121936-550b56aa.pptx
PDF
CAT 2024 VARC One - Shot Revision Marathon by Shabana.pptx.pdf
PPTX
Neurological complocations of systemic disease
PDF
Kalaari-SaaS-Founder-Playbook-2024-Edition-.pdf
PPTX
Diploma pharmaceutics notes..helps diploma students
hemostasis and its significance, physiology
Hospital Case Study .architecture design
principlesofmanagementsem1slides-131211060335-phpapp01 (1).ppt
Acidosis in Dairy Herds: Causes, Signs, Management, Prevention and Treatment
FYJC - Chemistry textbook - standard 11.
Cite It Right: A Compact Illustration of APA 7th Edition.pptx
MMW-CHAPTER-1-final.pptx major Elementary Education
Designing Adaptive Learning Paths in Virtual Learning Environments
faiz-khans about Radiotherapy Physics-02.pdf
4. Diagnosis and treatment planning in RPD.pptx
Chevening Scholarship Application and Interview Preparation Guide
CHALLENGES FACED BY TEACHERS WHEN TEACHING LEARNERS WITH DEVELOPMENTAL DISABI...
Key-Features-of-the-SHS-Program-v4-Slides (3) PPT2.pptx
PLASMA AND ITS CONSTITUENTS 123.pptx
hsl powerpoint resource goyloveh feb 07.ppt
pharmaceutics-1unit-1-221214121936-550b56aa.pptx
CAT 2024 VARC One - Shot Revision Marathon by Shabana.pptx.pdf
Neurological complocations of systemic disease
Kalaari-SaaS-Founder-Playbook-2024-Edition-.pdf
Diploma pharmaceutics notes..helps diploma students

Methods for handling deadlocks

  • 1. Methods for Handling Deadlocks Generally speaking, we can deal with the deadlock problem in one of three ways:  We can use a protocol to prevent or avoid deadlocks, ensuring that the system will never enter a deadlocked state.  We can allow the system to enter a deadlocked state, detect it, and recover.  We can ignore the problem altogether and pretend that deadlocks never occur in the system. Deadlock prevention provides a set of methods to ensure that at least one of the necessary conditions cannot hold. These methods prevent deadlocks by constraining how requests for resources can be made. Deadlock avoidance requires that the operating system be given additional information in advance concerning which resources a process will request and use during its lifetime. With this additional knowledge, the operating system can decide for each request whether or not the process should wait. To decide whether the current request can be satisfied or must be delayed, the system must consider the resources currently available, the resources currently allocated to each process, and the future requests and releases of each process. Deadlock Prevention We elaborate on this approach by examining each of the four necessary conditions separately Mutual Exclusion The mutual exclusion condition must hold. That is, at least one resource must be nonsharable. Sharable resources, in contrast, do not require mutually exclusive access and thus cannot be involved in a deadlock. Hold and Wait To ensure that the hold-and-wait condition never occurs in the system, we must guarantee that, whenever a process requests a resource, it does not hold any other resources. No Preemption The third necessary condition for deadlocks is that there be no preemption of resources that have already been allocated. To ensure that this condition does not hold, we can use the following protocol. If a process is holding some resources and requests another resource that cannot be immediately allocated to it (that is, the process must wait), then all resources the process is currently holding are preempted. In otherwords, these resources are implicitly released. The preempted resources are added to the list of resources for which the process is waiting. Circular wait To avoid circular wait, resources may be ordered and we can ensure that each process can request resources only in an increasing order of these numbers. Deadlock Avoidance Safe State A state is safe if the system can allocate resources to each process (up to its maximum) in some order and still avoid a deadlock. More formally, a system is in a safe state only if there exists a safe sequence. A sequence of processes <P1, P2, ..., Pn> is a safe sequence for the current allocation state if, for each Pi , the resource requests that Pi can still make can be satisfied by the currently available resources plus the resources held by all Pj, with j < i. In this situation, if the
  • 2. resources that Pi needs are not immediately available, then Pi can wait until all Pj have finished. When they have finished, Pi can obtain all of its needed resources, complete its designated task, return its allocated resources, and terminate. When Pi terminates, Pi+1 can obtain its needed resources, and so on. If no such sequence exists, then the system state is said to be unsafe. A safe state is not a deadlocked state. Conversely, a deadlocked state is an unsafe state. Not all unsafe states are deadlocks, however (Figure 7.6). An unsafe state may lead to a deadlock. Resource-Allocation-Graph Algorithm In addition to the request and assignment edges already described, we introduce a new type of edge, called a claim edge. A claim edge Pi → Rj indicates that process Pi may request resource Rj at some time in the future. This edge resembles a request edge in direction but is represented in the graph by a dashed line. When process Pi requests resource Rj , the claim edge Pi → Rj is converted to a request edge. Similarly, when a resource Rj is released by Pi , the assignment edge Rj → Pi is reconverted to a claim edge Pi → Rj . Now suppose that process Pi requests resource Rj. The request can be granted only if converting the request edge Pi → Rj to an assignment edge Rj → Pi does not result in the formation of a cycle in the resource-allocation graph. If no cycle exists, then the allocation of the resource will leave the system in a safe state. If a cycle is found, then the allocation will put the system in an unsafe state.
  • 3. To illustrate this algorithm, we consider the resource-allocation graph of Figure 7.7. Suppose that P2 requests R2. Although R2 is currently free, we cannot allocate it to P2, since this action will create a cycle in the graph (Figure 7.8). A cycle, as mentioned, indicates that the system is in an unsafe state. If P1 requests R2, and P2 requests R1, then a deadlock will occur.