Chapter 5 Deadlocks. Contents What is deadlock? What is deadlock? Characterization Characterization Resource allocation graph Resource allocation graph.

Slides:



Advertisements
Similar presentations
Chapter 7: Deadlocks.
Advertisements

1 Concurrency: Deadlock and Starvation Chapter 6.
Chapter 4 : Deadlock By : Jigar M. Pandya.
Deadlock and Starvation
DEADLOCK. Contents  Principles of deadlock  Deadlock prevention  Deadlock detection.
Chapter 7: Deadlocks.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 7: Deadlocks.
1 CSC 539: Operating Systems Structure and Design Spring 2005 Process deadlock  deadlock prevention  deadlock avoidance  deadlock detection  recovery.
DPNM Lab. Dept. of CSE, POSTECH
Deadlocks CS 3100 Deadlocks1. The Deadlock Problem A set of blocked processes each holding a resource and waiting to acquire a resource held by another.
1 Wednesday, June 28, 2006 Command, n.: Statement presented by a human and accepted by a computer in such a manner as to make the human feel that he is.
Chapter 7: Deadlocks. 7.2 Chapter Objectives To develop a description of deadlocks, which prevent sets of concurrent processes from completing their tasks.
1 School of Computing Science Simon Fraser University CMPT 300: Operating Systems I Ch 7: Deadlock Dr. Mohamed Hefeeda.
02/19/2008CSCI 315 Operating Systems Design1 Deadlock Notice: The slides for this lecture have been largely based on those accompanying the textbook Operating.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 7: Deadlocks.
1 School of Computing Science Simon Fraser University CMPT 300: Operating Systems I Ch 7: Deadlock Dr. Mohamed Hefeeda.
What we will cover…  The Deadlock Problem  System Model  Deadlock Characterization  Methods for Handling Deadlocks  Deadlock Prevention  Deadlock.
Deadlock Characterization
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 14, 2005 Objectives Understand the Deadlock.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Deadlocks.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 7: Deadlocks.
Cosc 4740 Chapter 6, Part 4 Deadlocks. The Deadlock Problem A set of blocked processes each holding a resource and waiting to acquire a resource held.
CHAPTER 8: DEADLOCKS System Model Deadlock Characterization
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 28 Handling Deadlock.
Operating Systems (CS 340 D) Princess Nora University Faculty of Computer & Information Systems Computer science Department.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 7: Deadlocks.
Chapter 8: Deadlocks Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance Deadlock Detection Recovery from Deadlock.
 The Deadlock Problem  System Model  Deadlock Characterization  Methods for Handling Deadlocks  Deadlock Prevention  Deadlock Avoidance  Deadlock.
Operating Systems (CS 340 D) Dr. Abeer Mahmoud Princess Nora University Faculty of Computer & Information Systems Computer science Department.
Chapter 7 Deadlocks Page 2 Chapter 7: Deadlocks System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 14, 2005 Chapter 7: Deadlocks The Deadlock.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 7: Deadlocks.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Lecture 7 Operating Systems.
Chapter 8 Deadlocks. Objective System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance Deadlock Detection.
7.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock Characterization.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock.
1 CS.217 Operating System By Ajarn..Sutapart Sappajak,METC,MSIT Chapter 6 Deadlocks Slide 1 Chapter 6 Deadlocks.
Deadlock. Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 6: Deadlocks.
Deadlock A deadlock is a situation wherein two or more competing actions are waiting for the other to finish, and thus neither ever does. Example : “When.
Lecture 6 Deadlock 1. Deadlock and Starvation Let S and Q be two semaphores initialized to 1 P 0 P 1 wait (S); wait (Q); wait (Q); wait (S);. signal (S);
Deadlock. Examples You can't get a job without experience; you can't get experience without a job. A set of blocked processes each holding a resource.
Chapter 7: Deadlocks. The Deadlock Problem System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 7: Deadlocks.
Chapter 7: Deadlocks.
OPERATING SYSTEM CONCEPTS AND PRACTISE
Chapter 7: Deadlocks.
Operating System Concepts
G.Anuradha Ref:- Galvin
Chapter 7: Deadlocks Source & Copyright: Operating System Concepts, Silberschatz, Galvin and Gagne.
Operating Systems (CS 340 D)
Chapter 7: Deadlocks.
Chapter 7 Deadlocks.
Chapter 7: Deadlocks.
Process Deadlocks.
Chapter 7: Deadlocks.
Deadlock B.Ramamurthy CSE421 1/11/2019 B.Ramamurthy.
G.Anuradha Ref:- Galvin
Deadlock B.Ramamurthy CSE421 2/23/2019 B.Ramamurthy.
Deadlocks Session - 13.
DEADLOCK.
Lecture 27 Syed Mansoor Sarwar
Chapter 7: Deadlocks.
Deadlock B.Ramamurthy CSE421 4/23/2019 B.Ramamurthy.
Deadlock B.Ramamurthy CSE421 5/1/2019 B.Ramamurthy.
Chapter 7: Deadlocks.
Chapter 7: Deadlocks.
Deadlock B.Ramamurthy CSE421 8/28/2019 B.Ramamurthy.
Deadlock B.Ramamurthy CSE421 9/3/2019 B.Ramamurthy.
Presentation transcript:

Chapter 5 Deadlocks

Contents What is deadlock? What is deadlock? Characterization Characterization Resource allocation graph Resource allocation graph Methods for handling deadlocks Methods for handling deadlocks Prevention Prevention Avoidance Avoidance Detection Detection

What is deadlock? System has several resources and several instances of each resource System has several resources and several instances of each resource Request can be satisfied by allocation of any instance of the type Request can be satisfied by allocation of any instance of the type Request made before use and released after use Request made before use and released after use Processes may make any number of resources – same or different type Processes may make any number of resources – same or different type Request and release are system calls Request and release are system calls Ex. Request and release device, open and close files, allocate and free memory Ex. Request and release device, open and close files, allocate and free memory

What is deadlock? A set of processes are in deadlock state if A set of processes are in deadlock state if when every process is waiting for an event that can be caused only by another process in the set when every process is waiting for an event that can be caused only by another process in the set Events are resource acquisition and release Events are resource acquisition and release Resource can be physical (disks, printers) or logical (files) Resource can be physical (disks, printers) or logical (files) Ex. Suppose there are 3 tape drives processes P1, P2, P3 are holding one each and if each is making a request for another – P1,P2, P3 are in deadlock state Ex. Suppose there are 3 tape drives processes P1, P2, P3 are holding one each and if each is making a request for another – P1,P2, P3 are in deadlock state

What is deadlock? Deadlock is possible that involves different resource types Deadlock is possible that involves different resource types Ex. System has 1 printer and 1 tape drive. Suppose that P1 is holding the tape drive and P2 holding the printer and P1 requesting printer and P2 requesting tape drive – a deadlock has occurred Ex. System has 1 printer and 1 tape drive. Suppose that P1 is holding the tape drive and P2 holding the printer and P1 requesting printer and P2 requesting tape drive – a deadlock has occurred Multithread programs are good candidates for deadlocks Multithread programs are good candidates for deadlocks

Characterization In a deadlock, processes never finish executing and system resources are tied up, preventing other jobs from starting In a deadlock, processes never finish executing and system resources are tied up, preventing other jobs from starting Features that characterize deadlock: Features that characterize deadlock: Mutual exclusion Mutual exclusion Hold and wait Hold and wait No preemption No preemption Circular wait Circular wait All these conditions must hold simultaneously in a system for deadlocks to occur All these conditions must hold simultaneously in a system for deadlocks to occur

Resource allocation graph Make 2 sets of vertices – one each for all active processes and other one for each resource Make 2 sets of vertices – one each for all active processes and other one for each resource A directed edge from P1 to R3 means that P1 has made request to R3 and waiting for allocation – request edge – inserted at the time request A directed edge from P1 to R3 means that P1 has made request to R3 and waiting for allocation – request edge – inserted at the time request Directed edge from R4 to P5 means that R4 has been allocated to P5 – assignment edge – request edge changes to assignment edge when request fulfilled – deleted after use and release Directed edge from R4 to P5 means that R4 has been allocated to P5 – assignment edge – request edge changes to assignment edge when request fulfilled – deleted after use and release No cycle in the graph – no set of processes in deadlock state No cycle in the graph – no set of processes in deadlock state Cycle in the graph deadlock may exist Cycle in the graph deadlock may exist

Methods for handling deadlocks 1.Prevention or avoidance 2.After deadlock has occurred, detect it and recover 3.Ignore the problem – pretend the problem never occurs Prevention: Ensure that one of the conditions cannot hold Prevention: Ensure that one of the conditions cannot hold Avoidance: OS will be informed about resources requests of each process during its lifetime – this additional knowledge can be used to decide if process should wait for a particular resource Avoidance: OS will be informed about resources requests of each process during its lifetime – this additional knowledge can be used to decide if process should wait for a particular resource

Handling deadlock If prevention or avoidance is not done, deadlock may occur – provide algorithm to detect deadlock and one more to recover from deadlock – second solution If prevention or avoidance is not done, deadlock may occur – provide algorithm to detect deadlock and one more to recover from deadlock – second solution If prevention or detection is done, and if deadlock occur, system performance deteriorate with more and processes asking for deadlocked resources and can collapse – OS reinstalled - third solution If prevention or detection is done, and if deadlock occur, system performance deteriorate with more and processes asking for deadlocked resources and can collapse – OS reinstalled - third solution This (3 rd ) is not viable approach, this is what is being done by most OS – cheaper This (3 rd ) is not viable approach, this is what is being done by most OS – cheaper Other options (wise) are very expensive and additional functions difficult to implement and must be used constantly Other options (wise) are very expensive and additional functions difficult to implement and must be used constantly

Prevention Mutual exclusion must hold for non-sharable resources – printers Mutual exclusion must hold for non-sharable resources – printers For resources like read only files it can be denied For resources like read only files it can be denied Mutual exclusion for all resources cant be denied Mutual exclusion for all resources cant be denied Hold and wait: Hold and wait: 1.Request granted only when no other is being held 2.Allow request only when process has none

Difference between 2 methods Ex. Copy data from tape to disk, sort the disk file and print Ex. Copy data from tape to disk, sort the disk file and print 1.Process must request tape, disk, printer perform copy, sort and print – printer is held though used much later 2.Allow process to request initially tape and disk to perform copy and sort When this is over release tape and disk. Request for disk and printer and when granted print operation takes place and finally release these two When this is over release tape and disk. Request for disk and printer and when granted print operation takes place and finally release these two Disadvantage: low resource utilization and starvation Disadvantage: low resource utilization and starvation

No preemption Can this condition be broken? Can this condition be broken? Possible: Possible: 1.If at the time of request the resource cant be allocated immediately, preempt all resources currently held – implicitly released 2.Has to make request again for old and new resources

No preemption 1.When request is made check availability 2.If available make allocation 3.If not, check if allocated to some other process and this process is waiting for additional resources – preempt the requested resources and make allocation to requesting process 4.If resources are not available or held by a waiting process the requesting process is put under wait state While waiting some its resources may be preempted While waiting some its resources may be preempted Process starts only all preempted and new requests are granted Process starts only all preempted and new requests are granted

Circular wait How this be broken? How this be broken? Processes request for resources in increasing order of enumeration Processes request for resources in increasing order of enumeration R1 be tape drive, R5 be disk drive, R12 be printer R1 be tape drive, R5 be disk drive, R12 be printer If a process requires tape drive and printer at the same time, first request tape drive and then for printer If a process requires tape drive and printer at the same time, first request tape drive and then for printer Should it require disk drive, printer must be released Should it require disk drive, printer must be released

Avoidance Prevention: Prevention: Prevent deadlocks by regulating requests and grants Prevent deadlocks by regulating requests and grants Restraints ensure that at least one of the four conditions is broken and hence deadlocks cant happen Restraints ensure that at least one of the four conditions is broken and hence deadlocks cant happen Avoidance: Avoidance: Gather additional information about how resources are to be requested by each process Gather additional information about how resources are to be requested by each process Ex. P require tape drive and printer Ex. P require tape drive and printer Q require printer and tape drive Q require printer and tape drive This situation can cause deadlock This situation can cause deadlock Use the knowledge gathered to decide whether wait for requests should happen Use the knowledge gathered to decide whether wait for requests should happen Thus avoid deadlock by making the process Q not join the wait queue for tape drive when it is using printer Thus avoid deadlock by making the process Q not join the wait queue for tape drive when it is using printer Resource allocation algorithm and bankers algorithm – to avoid deadlock Resource allocation algorithm and bankers algorithm – to avoid deadlock

Safe state State when system can allocate resources to each process in some order and still avoid deadlock – called safe state State when system can allocate resources to each process in some order and still avoid deadlock – called safe state Not all unsafe states are deadlock states Not all unsafe states are deadlock states Ensure that unsafe state never occur Ensure that unsafe state never occur When system enters unsafe state deadlocks can happen When system enters unsafe state deadlocks can happen Ex. R1 (tape drive) -12 units. P1, P2, P3 are 3 processes demanding R1. Ex. R1 (tape drive) -12 units. P1, P2, P3 are 3 processes demanding R1.

Safe state P1 P2 P3 P1 P2 P3 Max Needs Current allocation (at time t 0 ) No. of free R1 = 3 At time t 0 system is in safe state. satisfies safety conditions. Suppose at time t 1 P3 requests and one more of R1 and is allocated. System is no more in a safe state.

Sample P1 P2 P3 P1 P2 P3 Max Needs Current allocation (at time t 0 ) No. of free R1 = 2 No sequence of processes satisfy safety conditions. Hence unsafe state. Potential deadlock. No sequence of processes satisfy safety conditions. Hence unsafe state. Potential deadlock. Mistake is in granting the request of P3 Mistake is in granting the request of P3 Request to be granted only if it leaves the system in safe state Request to be granted only if it leaves the system in safe state

Resource allocation graph - revisited Same as before except that we make dashed edges when there is a claim for a resource (all requests for resources should be filed before) Same as before except that we make dashed edges when there is a claim for a resource (all requests for resources should be filed before)

Sample Deadlock Deadlock