Movatterモバイル変換


[0]ホーム

URL:


Uploaded byHarrisChikunya
PPTX, PDF32 views

Lecture 4 Deadlocks in operating systems.pptx

The document discusses deadlocks in operating systems, defining them and outlining four necessary conditions for their occurrence: mutual exclusion, hold and wait, no preemption, and circular wait. It explains strategies for deadlock prevention, avoidance, detection, and recovery, including resource allocation graphs and the famous banker’s algorithm. Additionally, it covers recovery methods, such as process termination and resource preemption, and mentions the 'ostrich algorithm' as a strategy of ignoring the issue.

Embed presentation

Download to read offline
1IT105Operating SystemsProcess Management: DeadlocksHarris Chikunya
2Objectives• By the end of this unit, you should be able to: Define a deadlocks; Discuss four conditions for a deadlock; Explain the ways of avoiding deadlocks; and Describe two ways to recover from the deadlock situation.
3Resources• There are two types of resources namely: Pre-emptable and Non-pre-emptable Resources.a) Pre-emptable Resources• This resource can be taken away from the process with no ill effects.Memory is an example of a pre-emptable resource.b) Non-preemptable Resource• This resource cannot be taken away from the process (without causing illeffect). For example, CD resources are not pre-emptable at any arbitrarymoment.• Under normal mode of operation, a process may utilize a resource inonly the following sequence: Request: If the request cannot be granted immediately, then therequesting process must wait until it can acquire the resource. Use: The process can operate on the resource. Release: The process releases the resource.
4Deadlocks• A process requests resources; if the resources are not available atthat time, the process enters a wait state.• It may happen that waiting processes will never again change state,because the resources they have requested are held by otherwaiting processes.• This situation is called a deadlock.
5Characterisation of a Deadlock1. Mutual Exclusion condition2. Hold and Wait condition3. No Preemption4. Circular Wait
6Mutual Exclusion Condition• The resources involved are non-shareable.• At least one resource must be held in a non-shareable mode, that is,only one process at a time claims exclusive control of the resource.• If another process requests that resource, the requesting must bedelayed until the resource has been released.
7Hold and Wait Condition• In this condition, a requesting process already holds resources andwaiting for the requested resources.• There must exist a process that is holding a resource already allocatedto it while waiting for additional resource that are currently beingheld by other processes.
8No-Preemption Condition• Resources already allocated to a process cannot be preempted.• Resources cannot be removed forcibly from the processes.• After completion, they will be released voluntarily by the processholding it.
9Circular Wait Condition• The processes in the system form a circular list or chain where eachprocess in the list is waiting for a resource held by the next processin the list.• There exists a set {P0, P1, …, P0} of waiting processes such that P0 iswaiting for a resource that is held by P1, P1 is waiting for a resourcethat is held by P2, …, Pn–1 is waiting for a resource that is held byPn, and P0 is waiting for a resource that is held by P0.
10Deadlock Example
11Resource allocation Graph• This graph consists of a set of vertices V and a set of edges E.• The set of vertices V is partitioned into two different types of nodes P = {PI,P2, ..., Pn}, the set consisting of all the active processes in the system, andR = {R1, R2, ..., Rm}, the set consisting of all resource types in the system.• A directed edge from process Pi to resource type Rj is denoted by Pi Rj; itsignifies that process Pi requested an instance of resource type Rj and is currentlywaiting for that resource.• A directed edge from resource type Rj to process Pi is denoted by Rj Pi; itsignifies that an instance of resource type Rj has been allocated to process Pi.
12Resource allocation Graph illustration
13Resource Allocation GraphThe following are the ways which will help you to check the grapheasily to predict the presence of a deadlock:(a) If no cycle exists in the resource allocation graph, there is nodeadlock.(b) If there is a cycle in the graph and each resource has only oneinstance, then there is a deadlock. In this case, a cycle is a necessaryand sufficient condition for deadlock.(c) If there is a cycle in the graph, and each resource has more thanone instance, there may or may not be a deadlock.
14Example• Suppose that process P3 requests an instance of resource type R2.Since no resource instance is currently available, a request edgeP3→ R2 is added to the graph.• At this point, two minimal cycles exist in the system:P1→R1→ P2→ R3→ P3→ R2→ P1P2→ R3 → P3→ R2→ P2
15Dealing with Deadlocks• In general, there are four strategies of dealing with deadlockproblem:1. Deadlock Prevention: Prevent deadlock by resource scheduling so asto negate at least one of the four conditions.2. Deadlock Avoidance: Avoid deadlock by careful resource scheduling.3. Deadlock Detection and Recovery: Detect deadlock and when itoccurs, take steps to recover.4. The Ostrich Approach: Just ignore the deadlock problem altogether.
16Deadlock Prevention1. Elimination of “Mutual Exclusion” Condition•The mutual exclusion condition must hold for non-shareableresources.•That is, several processes cannot simultaneously share a singleresource.•This condition is difficult to eliminate because some resources, suchas the disc drive and printer, are inherently non-shareable.•Note that shareable resources like read-only-file do not requiremutually exclusive access and thus cannot be involved in deadlock.
17Deadlock Prevention2. Elimination of “Hold and Wait” Condition• The first alternative is that a process request be granted all the resources itneeds at once, prior to execution.• The second alternative is to disallow a process from requesting resourceswhenever it has previously allocated resources.• This strategy requires that all the resources a process will need must berequested at once.• The system must grant resources on “all or none” basis.• If the complete set of resources needed by a process is not currentlyavailable, then the process must wait until the complete set is available.• While the process waits, however, it may not hold any resources.• Thus the “wait for” condition is denied and deadlocks simply cannot occur.• This strategy can lead to serious waste of resources.
18Deadlock Prevention3. Elimination of “Non-preemption” Condition• The non-preemption condition can be alleviated by forcing a processwaiting for a resource that cannot immediately be allocated to relinquishall of its currently held resources, so that other processes may use themto finish.• This strategy requires that when a process that is holding some resourcesis denied a request for additional resources.• The process must release its held resources and, if necessary, requestthem again together with additional resources.• Implementation of this strategy denies the “no-preemptive” conditioneffectively.
19Deadlock Prevention4. Elimination of “Circular Wait” Condition•The last condition, the circular wait, can be denied by imposing atotal ordering on all of the resource types and then forcing, allprocesses to request the resources in order (increasing ordecreasing).•This strategy impose a total ordering of all resources types, and torequire that each process requests resources in a numerical order(increasing or decreasing) of enumeration.•With this rule, the resource allocation graph can never have a cycle.
20Deadlock Avoidance• This approach to the deadlock problem anticipates deadlock beforeit actually occurs.• This approach employs an algorithm to access the possibility thatdeadlock could occur and acting accordingly.• If the necessary conditions for a deadlock are in place, it is stillpossible to avoid deadlock by being careful when resources areallocated.• It employs the most famous deadlock avoidance algorithm that isthe Banker’s algorithm.
21Deadlock Detection and RecoveryDeadlock Detection• Detection of deadlocks is the most practical policy, which being bothliberal and cost efficient most operating systems deploy.• To detect a deadlock, we must go about in a recursive manner andsimulate the most favoured execution of each unblocked process:(a) An unblocked process may acquire all the needed resources and willexecute;(b) It will then release all the acquired resources and remain dormantthereafter;(c) The now released resources may wake up some previously blockedprocess;(d) Continue the above steps as long as possible; and(e) If any blocked processes remain, they are deadlocked.
22Deadlock Detection and RecoveryRECOVERY FROM DEADLOCK• There are various options for breaking a deadlock.1. Recovery by Process Termination• Abort all deadlocked processes: This method will break the deadlockcycle clearly by terminating all process.• This method is cost effective.• Abort one process at a time until the deadlock cycle is eliminated: Thismethod terminates one process at a time, and invokes a deadlock-detection algorithm to determine whether any processes are stilldeadlocked.
23Deadlock Detection and RecoveryRECOVERY FROM DEADLOCK2. Recovery by Resource Pre-emption the operator or system pre-empts some resources from processes andgive these resources to other processes until the deadlock cycle isbroken. If pre-emption is required to deal with deadlocks, then three issuesneed to be addressed:• Selecting a victim: The system or operator selects which resources andwhich processes are to be pre-empted based on cost factor.• Rollback: The system or operator must roll back the process to some safestate and restart it from that state.• Starvation: The system or operator should ensure that resources will notalways be pre-empted from the same process?
24Ostrich Algorithm• It is hoped that deadlock doesn’t happen• In general, this is a reasonable strategy.• Deadlock is unlikely to occur very often; a system can run for yearswithout deadlock occurring.
25ACTIVITY1. What is the purpose of deadlock?2. What is the different between process nodes and resource nodes ?3. What is a deadlock and what are the four conditions that will createthe deadlock situation?4. How can deadlock be avoided? Explain with the help of an example.
26End

Recommended

PPTX
Algorithm 4Chapter Four- Deadlock (5).pptx
PPTX
Ch 4 deadlock
PPTX
operating system memory management with example
PPTX
Deadlocks
PPTX
Deadlocks and Deadlock Detection Other Issues
PPT
3 (2).ppt
PPT
3 (1) [Autosaved].ppt
PPTX
Operting System- unit5-part1_Deadlock.pptx
PPT
Os module 2 d
PPTX
Deadlock
PPT
A ppt on deadlock in operating systems for the better explanation
PPTX
Deadlock and memory management -- Operating System
PDF
operating system deadlock how to handle it
PPTX
Deadlock
PPT
Deadlock
PDF
OS-Part-06.pdf
PPTX
dead lock in operating system Presentation1.pptx
PPTX
Deadlocks
PPTX
Deadlock detection & prevention
PPTX
deadlock im operating system and their solution.pptx
PPTX
deadlock in OS.pptx
PPT
Deadlocks
PPT
Chapter 03
PPTX
osvzjsjjdndnnssnnsnsndndndnndeadlock.pptx
PPTX
Gp1242 007 oer ppt
PDF
9 deadlock
PPTX
CSE34115 1115 - Ch-06 Concurrency 2.pptx
PDF
Cheryl Hung, Vibe Coding Auth Without Melting Down! isaqb Software Architectu...
PPTX
Support, Monitoring, Continuous Improvement & Scaling Agentic Automation [3/3]

More Related Content

PPTX
Algorithm 4Chapter Four- Deadlock (5).pptx
PPTX
Ch 4 deadlock
PPTX
operating system memory management with example
PPTX
Deadlocks
PPTX
Deadlocks and Deadlock Detection Other Issues
PPT
3 (2).ppt
PPT
3 (1) [Autosaved].ppt
Algorithm 4Chapter Four- Deadlock (5).pptx
Ch 4 deadlock
operating system memory management with example
Deadlocks
Deadlocks and Deadlock Detection Other Issues
3 (2).ppt
3 (1) [Autosaved].ppt

Similar to Lecture 4 Deadlocks in operating systems.pptx

PPTX
Operting System- unit5-part1_Deadlock.pptx
PPT
Os module 2 d
PPTX
Deadlock
PPT
A ppt on deadlock in operating systems for the better explanation
PPTX
Deadlock and memory management -- Operating System
PDF
operating system deadlock how to handle it
PPTX
Deadlock
PPT
Deadlock
PDF
OS-Part-06.pdf
PPTX
dead lock in operating system Presentation1.pptx
PPTX
Deadlocks
PPTX
Deadlock detection & prevention
PPTX
deadlock im operating system and their solution.pptx
PPTX
deadlock in OS.pptx
PPT
Deadlocks
PPT
Chapter 03
PPTX
osvzjsjjdndnnssnnsnsndndndnndeadlock.pptx
PPTX
Gp1242 007 oer ppt
PDF
9 deadlock
PPTX
CSE34115 1115 - Ch-06 Concurrency 2.pptx
Operting System- unit5-part1_Deadlock.pptx
Os module 2 d
Deadlock
A ppt on deadlock in operating systems for the better explanation
Deadlock and memory management -- Operating System
operating system deadlock how to handle it
Deadlock
Deadlock
OS-Part-06.pdf
dead lock in operating system Presentation1.pptx
Deadlocks
Deadlock detection & prevention
deadlock im operating system and their solution.pptx
deadlock in OS.pptx
Deadlocks
Chapter 03
osvzjsjjdndnnssnnsnsndndndnndeadlock.pptx
Gp1242 007 oer ppt
9 deadlock
CSE34115 1115 - Ch-06 Concurrency 2.pptx

Recently uploaded

PDF
Cheryl Hung, Vibe Coding Auth Without Melting Down! isaqb Software Architectu...
PPTX
Support, Monitoring, Continuous Improvement & Scaling Agentic Automation [3/3]
PDF
Mulesoft Meetup Online Portuguese: MCP e IA
PDF
Beyond Basics: How to Build Scalable, Intelligent Imagery Pipelines
PPTX
kernel PPT (Explanation of Windows Kernal).pptx
PDF
[BDD 2025 - Mobile Development] Exploring Apple’s On-Device FoundationModels
PDF
So You Want to Work at Google | DevFest Seattle 2025
PPTX
"Feelings versus facts: why metrics are more important than intuition", Igor ...
 
PDF
Mastering Agentic Orchestration with UiPath Maestro | Hands on Workshop
PDF
[BDD 2025 - Full-Stack Development] The Modern Stack: Building Web & AI Appli...
PDF
[BDD 2025 - Full-Stack Development] PHP in AI Age: The Laravel Way. (Rizqy Hi...
PDF
The Evolving Role of the CEO in the Age of AI
PDF
[BDD 2025 - Artificial Intelligence] AI for the Underdogs: Innovation for Sma...
PDF
DUBAI IT MODERNIZATION WITH AZURE MANAGED SERVICES.pdf
PDF
The Necessity of Digital Forensics, the Digital Forensics Process & Laborator...
PDF
10 Best Automation QA Testing Software Tools in 2025.pdf
PPTX
Guardrails in Action - Ensuring Safe AI with Azure AI Content Safety.pptx
PDF
[BDD 2025 - Mobile Development] Crafting Immersive UI with E2E and AGSL Shade...
PDF
The partnership effect: Libraries and publishers on collaborating and thrivin...
PPTX
How to Choose the Right Vendor for ADA PDF Accessibility and Compliance in 2026
Cheryl Hung, Vibe Coding Auth Without Melting Down! isaqb Software Architectu...
Support, Monitoring, Continuous Improvement & Scaling Agentic Automation [3/3]
Mulesoft Meetup Online Portuguese: MCP e IA
Beyond Basics: How to Build Scalable, Intelligent Imagery Pipelines
kernel PPT (Explanation of Windows Kernal).pptx
[BDD 2025 - Mobile Development] Exploring Apple’s On-Device FoundationModels
So You Want to Work at Google | DevFest Seattle 2025
"Feelings versus facts: why metrics are more important than intuition", Igor ...
 
Mastering Agentic Orchestration with UiPath Maestro | Hands on Workshop
[BDD 2025 - Full-Stack Development] The Modern Stack: Building Web & AI Appli...
[BDD 2025 - Full-Stack Development] PHP in AI Age: The Laravel Way. (Rizqy Hi...
The Evolving Role of the CEO in the Age of AI
[BDD 2025 - Artificial Intelligence] AI for the Underdogs: Innovation for Sma...
DUBAI IT MODERNIZATION WITH AZURE MANAGED SERVICES.pdf
The Necessity of Digital Forensics, the Digital Forensics Process & Laborator...
10 Best Automation QA Testing Software Tools in 2025.pdf
Guardrails in Action - Ensuring Safe AI with Azure AI Content Safety.pptx
[BDD 2025 - Mobile Development] Crafting Immersive UI with E2E and AGSL Shade...
The partnership effect: Libraries and publishers on collaborating and thrivin...
How to Choose the Right Vendor for ADA PDF Accessibility and Compliance in 2026

Lecture 4 Deadlocks in operating systems.pptx

  • 1.
  • 2.
    2Objectives• By theend of this unit, you should be able to: Define a deadlocks; Discuss four conditions for a deadlock; Explain the ways of avoiding deadlocks; and Describe two ways to recover from the deadlock situation.
  • 3.
    3Resources• There aretwo types of resources namely: Pre-emptable and Non-pre-emptable Resources.a) Pre-emptable Resources• This resource can be taken away from the process with no ill effects.Memory is an example of a pre-emptable resource.b) Non-preemptable Resource• This resource cannot be taken away from the process (without causing illeffect). For example, CD resources are not pre-emptable at any arbitrarymoment.• Under normal mode of operation, a process may utilize a resource inonly the following sequence: Request: If the request cannot be granted immediately, then therequesting process must wait until it can acquire the resource. Use: The process can operate on the resource. Release: The process releases the resource.
  • 4.
    4Deadlocks• A processrequests resources; if the resources are not available atthat time, the process enters a wait state.• It may happen that waiting processes will never again change state,because the resources they have requested are held by otherwaiting processes.• This situation is called a deadlock.
  • 5.
    5Characterisation of aDeadlock1. Mutual Exclusion condition2. Hold and Wait condition3. No Preemption4. Circular Wait
  • 6.
    6Mutual Exclusion Condition•The resources involved are non-shareable.• At least one resource must be held in a non-shareable mode, that is,only one process at a time claims exclusive control of the resource.• If another process requests that resource, the requesting must bedelayed until the resource has been released.
  • 7.
    7Hold and WaitCondition• In this condition, a requesting process already holds resources andwaiting for the requested resources.• There must exist a process that is holding a resource already allocatedto it while waiting for additional resource that are currently beingheld by other processes.
  • 8.
    8No-Preemption Condition• Resourcesalready allocated to a process cannot be preempted.• Resources cannot be removed forcibly from the processes.• After completion, they will be released voluntarily by the processholding it.
  • 9.
    9Circular Wait Condition•The processes in the system form a circular list or chain where eachprocess in the list is waiting for a resource held by the next processin the list.• There exists a set {P0, P1, …, P0} of waiting processes such that P0 iswaiting for a resource that is held by P1, P1 is waiting for a resourcethat is held by P2, …, Pn–1 is waiting for a resource that is held byPn, and P0 is waiting for a resource that is held by P0.
  • 10.
  • 11.
    11Resource allocation Graph•This graph consists of a set of vertices V and a set of edges E.• The set of vertices V is partitioned into two different types of nodes P = {PI,P2, ..., Pn}, the set consisting of all the active processes in the system, andR = {R1, R2, ..., Rm}, the set consisting of all resource types in the system.• A directed edge from process Pi to resource type Rj is denoted by Pi Rj; itsignifies that process Pi requested an instance of resource type Rj and is currentlywaiting for that resource.• A directed edge from resource type Rj to process Pi is denoted by Rj Pi; itsignifies that an instance of resource type Rj has been allocated to process Pi.
  • 12.
  • 13.
    13Resource Allocation GraphThefollowing are the ways which will help you to check the grapheasily to predict the presence of a deadlock:(a) If no cycle exists in the resource allocation graph, there is nodeadlock.(b) If there is a cycle in the graph and each resource has only oneinstance, then there is a deadlock. In this case, a cycle is a necessaryand sufficient condition for deadlock.(c) If there is a cycle in the graph, and each resource has more thanone instance, there may or may not be a deadlock.
  • 14.
    14Example• Suppose thatprocess P3 requests an instance of resource type R2.Since no resource instance is currently available, a request edgeP3→ R2 is added to the graph.• At this point, two minimal cycles exist in the system:P1→R1→ P2→ R3→ P3→ R2→ P1P2→ R3 → P3→ R2→ P2
  • 15.
    15Dealing with Deadlocks•In general, there are four strategies of dealing with deadlockproblem:1. Deadlock Prevention: Prevent deadlock by resource scheduling so asto negate at least one of the four conditions.2. Deadlock Avoidance: Avoid deadlock by careful resource scheduling.3. Deadlock Detection and Recovery: Detect deadlock and when itoccurs, take steps to recover.4. The Ostrich Approach: Just ignore the deadlock problem altogether.
  • 16.
    16Deadlock Prevention1. Eliminationof “Mutual Exclusion” Condition•The mutual exclusion condition must hold for non-shareableresources.•That is, several processes cannot simultaneously share a singleresource.•This condition is difficult to eliminate because some resources, suchas the disc drive and printer, are inherently non-shareable.•Note that shareable resources like read-only-file do not requiremutually exclusive access and thus cannot be involved in deadlock.
  • 17.
    17Deadlock Prevention2. Eliminationof “Hold and Wait” Condition• The first alternative is that a process request be granted all the resources itneeds at once, prior to execution.• The second alternative is to disallow a process from requesting resourceswhenever it has previously allocated resources.• This strategy requires that all the resources a process will need must berequested at once.• The system must grant resources on “all or none” basis.• If the complete set of resources needed by a process is not currentlyavailable, then the process must wait until the complete set is available.• While the process waits, however, it may not hold any resources.• Thus the “wait for” condition is denied and deadlocks simply cannot occur.• This strategy can lead to serious waste of resources.
  • 18.
    18Deadlock Prevention3. Eliminationof “Non-preemption” Condition• The non-preemption condition can be alleviated by forcing a processwaiting for a resource that cannot immediately be allocated to relinquishall of its currently held resources, so that other processes may use themto finish.• This strategy requires that when a process that is holding some resourcesis denied a request for additional resources.• The process must release its held resources and, if necessary, requestthem again together with additional resources.• Implementation of this strategy denies the “no-preemptive” conditioneffectively.
  • 19.
    19Deadlock Prevention4. Eliminationof “Circular Wait” Condition•The last condition, the circular wait, can be denied by imposing atotal ordering on all of the resource types and then forcing, allprocesses to request the resources in order (increasing ordecreasing).•This strategy impose a total ordering of all resources types, and torequire that each process requests resources in a numerical order(increasing or decreasing) of enumeration.•With this rule, the resource allocation graph can never have a cycle.
  • 20.
    20Deadlock Avoidance• Thisapproach to the deadlock problem anticipates deadlock beforeit actually occurs.• This approach employs an algorithm to access the possibility thatdeadlock could occur and acting accordingly.• If the necessary conditions for a deadlock are in place, it is stillpossible to avoid deadlock by being careful when resources areallocated.• It employs the most famous deadlock avoidance algorithm that isthe Banker’s algorithm.
  • 21.
    21Deadlock Detection andRecoveryDeadlock Detection• Detection of deadlocks is the most practical policy, which being bothliberal and cost efficient most operating systems deploy.• To detect a deadlock, we must go about in a recursive manner andsimulate the most favoured execution of each unblocked process:(a) An unblocked process may acquire all the needed resources and willexecute;(b) It will then release all the acquired resources and remain dormantthereafter;(c) The now released resources may wake up some previously blockedprocess;(d) Continue the above steps as long as possible; and(e) If any blocked processes remain, they are deadlocked.
  • 22.
    22Deadlock Detection andRecoveryRECOVERY FROM DEADLOCK• There are various options for breaking a deadlock.1. Recovery by Process Termination• Abort all deadlocked processes: This method will break the deadlockcycle clearly by terminating all process.• This method is cost effective.• Abort one process at a time until the deadlock cycle is eliminated: Thismethod terminates one process at a time, and invokes a deadlock-detection algorithm to determine whether any processes are stilldeadlocked.
  • 23.
    23Deadlock Detection andRecoveryRECOVERY FROM DEADLOCK2. Recovery by Resource Pre-emption the operator or system pre-empts some resources from processes andgive these resources to other processes until the deadlock cycle isbroken. If pre-emption is required to deal with deadlocks, then three issuesneed to be addressed:• Selecting a victim: The system or operator selects which resources andwhich processes are to be pre-empted based on cost factor.• Rollback: The system or operator must roll back the process to some safestate and restart it from that state.• Starvation: The system or operator should ensure that resources will notalways be pre-empted from the same process?
  • 24.
    24Ostrich Algorithm• Itis hoped that deadlock doesn’t happen• In general, this is a reasonable strategy.• Deadlock is unlikely to occur very often; a system can run for yearswithout deadlock occurring.
  • 25.
    25ACTIVITY1. What isthe purpose of deadlock?2. What is the different between process nodes and resource nodes ?3. What is a deadlock and what are the four conditions that will createthe deadlock situation?4. How can deadlock be avoided? Explain with the help of an example.
  • 26.

Editor's Notes

  • #3 Before studying about deadlocks, let us look at the various types of resources. A process must request a resource before using it, and mustrelease the resource after using it.•A process may request as many resources as it requires tocarry out its designated task.
  • #4 A deadlock is a situation where a group of processes is permanently blocked as a result of each process having acquired a set of resources needed for its completion and having to wait for the release of the remaining resources held by others thus making it impossible for any of the deadlocked processes to proceed. The simplest example of deadlock is where process 1 has been allocated a non-shareable resource A, say, a CD drive, and process 2 has been allocated a non-sharable resource B, say, a printer. Now, if it turns out that process 1 needs resource B (printer) to proceed and process 2 needs resource A (the CD drive) to proceed and these are the only two processes in the system, each has blocked the other and all useful work in the system stops.
  • #5 In a deadlock, processes never finish executing and system resources are tied up, preventing other jobs from ever starting.• Before we discuss the various methods for dealing with the deadlock problem, we shall describe features that characterize deadlocks.Coffman (1971) identified four necessary conditions that must hold simultaneously for a deadlock to occur.
  • #10 Consider the traffic deadlock shown in the Figure Consider each section of the street as a resource. In this situation: (a) Mutual exclusion condition applies, since only one vehicle can be on a section of the street at a time. (b) Hold-and-wait condition applies, since each vehicle is occupying a section of the street, and waiting to move on to the next section of the street. (c) Non-preemptive condition applies, since a section of the street that is occupied by a vehicle cannot be taken away from it. (d) Circular wait condition applies, since each vehicle is waiting for the next vehicle to move. That is, each vehicle in the traffic is waiting for a section of the street held by the next vehicle in the traffic.
  • #11 Deadlocks can be described in terms of a directed graph called a system resource-allocation graph.A directed edge Pi Rj is called a request edge.A directed edge RjPi is called an assignment edge.
  • #12 The resource-allocation graph shown below depicts the following situation.Resource instances:• One instance of resource type R1• Two instances of resource type R2• One instance of resource type R3• Three instances of resource type R4Process states:• Process PI is holding an instance of resource type R2, and is waiting for an instance of resource type R1.• Process P2 is holding an instance of R1 and R2, and is waiting for an instance of resource type R3.• Process P3 is holding an instance of R3.
  • #13 We can use these graphs to determine if a deadline has occurred or may occur
  • #14 Processes PI, P2, and P3 are deadlocked. Process P2 is waiting for the resource R3, which is held by process P3. Process P3, on the other hand, is waiting for either process PI or process P2 to release resource R2. In addition, process PI is waiting for process P2 to release resource R1.Now consider the resource-allocation graph on the right. In this example, we also have acycle However, there is no deadlock. Observe that process P4 may release its instance of resource type R2.That resource can then be allocated to P3, breaking the cycle.
  • #15 Let’s examine each strategy one by one to evaluate their respective strengths and weaknesses.
  • #16 since all four of the conditions are necessary for deadlock to occur, it follows that deadlock might be prevented by denying any one of the 4 conditions.
  • #17 There are two possibilities for the elimination of the this condition. For example, a program requiring ten tap drives must request and receive all ten drives before it begins executing. If the program needs only one tap drive to begin execution and then does not need the remaining tap drives for several hours then substantial computer resources (nine tape drives) will sit idle for several hours. This strategy can cause indefinite postponement (starvation), since not all the required resources may become available at once.
  • #19 For example, provide a global numbering of all the resources, as shown1 ≡ Card reader2 ≡ Printer3 ≡ Optical driver4 ≡ HDD5 ≡ Card punchNow the rule is this: processes can request resources whenever they want to, but all requests must be made in numerical order. A process may request first printer and then a HDD(order: 2, 4), but it may not request first a optical driver and then a printer (order: 3, 2). The problem with this strategy is that it may be impossible to find an ordering that satisfies everyone.
  • #20 The Banker's algorithm is a resource allocation & deadlock avoidance algorithm developed by EdsgerDijkstra that test for safety by simulating the allocation of pre-determined maximum possible amounts of allresources. Then it makes a "safe-state" check to test for possible deadlock conditions for all other pendingactivities, before deciding whether allocation should be allowed to continue.The Banker's algorithm is run by the operating system whenever a process requests resources. Thealgorithm prevents deadlock by denying or postponing the request if it determines that accepting the requestcould put the system in an unsafe state (one where deadlock could occur).
  • #22 When a detection algorithm determines that a deadlock exists, then the system or operator is responsible for handling deadlock problem.Deadlock recovery is generally used when deadlocks are rare, and the cost of recovery (process termination or rollback) is low.

[8]ページ先頭

©2009-2025 Movatter.jp