Deadlocks - System Model - Deadlock characterization - Methods for handling deadlocks - Deadlock prevention,avoidance - Deadlock detection and recovery.

Slides:



Advertisements
Similar presentations
Chapter 7: Deadlocks.
Advertisements

Chapter 7: Deadlocks.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 7: Deadlocks.
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.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 8: Deadlocks System Model Deadlock Characterization Methods for Handling Deadlocks.
Chapter 7: Deadlocks. 7.2 Chapter Objectives To develop a description of deadlocks, which prevent sets of concurrent processes from completing their tasks.
1 Chapter 7: Deadlock. 2 The Deadlock Problem 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.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 7: Deadlocks.
Deadlocks Gordon College Stephen Brinton. Deadlock Overview The Deadlock Problem System Model Deadlock Characterization Methods for Handling Deadlocks.
What we will cover…  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 Deadlocks.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 8: Deadlocks System Model Deadlock Characterization Methods for Handling Deadlocks.
Chapter 7: Deadlocks Adapted to COP4610 by Robert van Engelen.
System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention, Avoidance, and Detection Recovering from Deadlock Combined Approach.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 7: Deadlocks.
Chapter 7 Deadlocks. 7.2 Modified By Dr. Khaled Wassif Operating System Concepts – 7 th Edition Silberschatz, Galvin and Gagne ©2005 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.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-6 Deadlocks Department of Computer Science and Software Engineering.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 AE4B33OSS Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock Characterization.
CHAPTER 8: DEADLOCKS System Model Deadlock Characterization
 The Deadlock Problem  System Model  Deadlock Characterization  Methods for Handling Deadlocks  Deadlock Prevention  Deadlock Avoidance  Deadlock.
Dr. Kalpakis CMSC 421, Operating Systems Deadlocks.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 7: Deadlocks System Model Deadlock Characterization Methods.
Styresystemer og Multiprogrammering Block 3, 2005 Deadlocks Robert Glück.
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.
Chapter 7: Deadlocks. 7.2CSCI 380 – Operating Systems Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock Characterization Methods for Handling.
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.
CS307 Operating Systems Deadlocks Fan Wu Department of Computer Science and Engineering Shanghai Jiao Tong University Spring 2012.
Chap 7 Deadlocks. Chapter Objectives To develop a description of deadlocks, which prevent sets of concurrent processes from completing their tasks To.
1 CS.217 Operating System By Ajarn..Sutapart Sappajak,METC,MSIT Chapter 6 Deadlocks Slide 1 Chapter 6 Deadlocks.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 8: Deadlocks System Model Deadlock Characterization Methods for Handling Deadlocks.
Deadlocks Introduction to Operating Systems: Module 7.
7.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 7: Deadlocks.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock.
7.1 CSE Department MAITSandeep Tayal 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.
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.
Thursday, February 23, 2012 Chapter 6 homework questions?
Chapter 7: Deadlocks.
OPERATING SYSTEM CONCEPTS AND PRACTISE
Chapter 7: Deadlocks.
G.Anuradha Ref:- Galvin
Chapter 7: Deadlocks.
Operating System: DEADLOCKS
Process Deadlocks.
Deadlock B.Ramamurthy CSE421 1/11/2019 B.Ramamurthy.
Lecture 6: Deadlocks, Deadlock Risk Management
G.Anuradha Ref:- Galvin
Chapter 7: Deadlocks.
Outline Deadlocks, dead lock prevention, avoidance.
Deadlock Prevention Restrain the ways request can be made.
Deadlock B.Ramamurthy CSE421 2/23/2019 B.Ramamurthy.
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.
OPERATING SYSTEM CONCEPTS
Deadlock B.Ramamurthy CSE421 8/28/2019 B.Ramamurthy.
Deadlock B.Ramamurthy CSE421 9/3/2019 B.Ramamurthy.
Presentation transcript:

Deadlocks - System Model - Deadlock characterization - Methods for handling deadlocks - Deadlock prevention,avoidance - Deadlock detection and recovery - System Model - Deadlock characterization - Methods for handling deadlocks - Deadlock prevention,avoidance - Deadlock detection and recovery Topics

The Deadlock Problem - A set of blocked processes each holding a resource and waiting to acquire a resource held by another process in the set. - Example: System has two tape drives. Process P_1 and P_2 each holds one and needs the other tape. - Example: P1: wait(B); wait(A); P2: wait(A); wait(B); - A set of blocked processes each holding a resource and waiting to acquire a resource held by another process in the set. - Example: System has two tape drives. Process P_1 and P_2 each holds one and needs the other tape. - Example: P1: wait(B); wait(A); P2: wait(A); wait(B);

Bridge Crossing Example - Traffic only in one direction - Each direction of a bridge can be viewed as resource. - If a deadlock occurs, it can be resolved if one car backs up (preempt and rollback) - Backing up may be impossible - Starvation is possible - Traffic only in one direction - Each direction of a bridge can be viewed as resource. - If a deadlock occurs, it can be resolved if one car backs up (preempt and rollback) - Backing up may be impossible - Starvation is possible

System Model Resource types R 1, R2, …, R_{m-1} CPU cycles, memory space, I/o devices Each resource type R_I has W_I instances Each process utilizes a resource as follows: - request, use and release Resource types R 1, R2, …, R_{m-1} CPU cycles, memory space, I/o devices Each resource type R_I has W_I instances Each process utilizes a resource as follows: - request, use and release

Deadlock Characterization Deadlock can arise if four conditions hold simultaneously. - Mutual Exclusion - Hold and Wait - No preemption - Circular Wait Deadlock can arise if four conditions hold simultaneously. - Mutual Exclusion - Hold and Wait - No preemption - Circular Wait

Resource-Allocation Graph A set of vertices V and edges E V is partitioned into two types: -P={P1,P2,…,Pn}, the set consisting of all the processes in the system and R={R1,R2,…,Rm}, the set consisting of all resources in the system. Request edge - directed edge from Pi to Rj Assignment edge - directed edge from Rj to Pi. A set of vertices V and edges E V is partitioned into two types: -P={P1,P2,…,Pn}, the set consisting of all the processes in the system and R={R1,R2,…,Rm}, the set consisting of all resources in the system. Request edge - directed edge from Pi to Rj Assignment edge - directed edge from Rj to Pi.

Resource-Allocation Graph Process Resources type with 4 instances Pi Requests an instance of Rj

Example of a Graph with no cycle P1 R1 R2 R3 P3P2 R4

Example of a graph with a cycle P1 R1 R2 P2 P3 P4

Basic Facts - If a graph contains no cycle implies no deadlock - If a graph contains a cycle - if only one instance per resource type then there is dead lock - If several instances per resource type possibility of dead lock. - If a graph contains no cycle implies no deadlock - If a graph contains a cycle - if only one instance per resource type then there is dead lock - If several instances per resource type possibility of dead lock.

Methods for Handling Deadlocks - Ensure that the system will never enter a deadlock state. - Allow the system to enter a deadlock state and then recover. - Ignore the problem and pretend that deadlocks never occur in the system; - Ensure that the system will never enter a deadlock state. - Allow the system to enter a deadlock state and then recover. - Ignore the problem and pretend that deadlocks never occur in the system;

Deadlock prevention - Restrain the ways resource requests are made. - Hold and wait - must guarantee that whenever a process requests a resource, it does not hold any other resources - either request before a process begins execution or when the process has none - Low resource utilization - starvation possible. - Restrain the ways resource requests are made. - Hold and wait - must guarantee that whenever a process requests a resource, it does not hold any other resources - either request before a process begins execution or when the process has none - Low resource utilization - starvation possible.

Deadlock prevention No preemption - if a process requests a resource that cannot be allocated, all currently held resources are released. Circular wait - imposes a total ordering of all resource types, and require that each process requests resources in an increasing order of enumeration. No preemption - if a process requests a resource that cannot be allocated, all currently held resources are released. Circular wait - imposes a total ordering of all resource types, and require that each process requests resources in an increasing order of enumeration.

Deadlock Avoidance Requires that the system a priori information available maximum number of resources needed. Dead-lock avoidance algorithm dynamically examines the resource- allocation to ensure that there is no circular wait. Resource allocation state is defined by the number of available and allocated resources and the maximum demands. Requires that the system a priori information available maximum number of resources needed. Dead-lock avoidance algorithm dynamically examines the resource- allocation to ensure that there is no circular wait. Resource allocation state is defined by the number of available and allocated resources and the maximum demands.

Safe State When a process requests an available resource, system must decide if immediate allocation leaves the system in a safe state. System is in a safe state if there exists a safe sequence for all processes. Sequence is safe for each Pi, if the requests of Pi- can still request can be satisfied by currently available resources and resources held by Pj with j < I. When a process requests an available resource, system must decide if immediate allocation leaves the system in a safe state. System is in a safe state if there exists a safe sequence for all processes. Sequence is safe for each Pi, if the requests of Pi- can still request can be satisfied by currently available resources and resources held by Pj with j < I.

Basic Facts - If a system is in safe state implies no deadlocks. - If a system is in unsafe state implies possibility of deadlock. - Avoidance implies ensure that a system will never enter an unsafe state. - If a system is in safe state implies no deadlocks. - If a system is in unsafe state implies possibility of deadlock. - Avoidance implies ensure that a system will never enter an unsafe state.

Banker’s Algorithm Multiple instances Each process must a priori claim maximum use. - When a process requests a resource it may have to wait. - When a process gets all its resources it must return them in a finite amount of time. Multiple instances Each process must a priori claim maximum use. - When a process requests a resource it may have to wait. - When a process gets all its resources it must return them in a finite amount of time.

Data Structures for the Banker’s Algorithm N= number of processes, m= available resources Available- vector Available[j]=k means that there are k instances of resource types Rj. Allocation -n x m matrix If Allocation[I,j]=k means process Pi has been allocated k units of resource type Rj. N= number of processes, m= available resources Available- vector Available[j]=k means that there are k instances of resource types Rj. Allocation -n x m matrix If Allocation[I,j]=k means process Pi has been allocated k units of resource type Rj.

Data Structures for the Banker’s Algorithm (continued) Need - n x m matrix. If Need[I,j]=m means process Pi needs m units of resource type Rj. Need[I,j]=Max[I,j]-Allocation[I,j] Need - n x m matrix. If Need[I,j]=m means process Pi needs m units of resource type Rj. Need[I,j]=Max[I,j]-Allocation[I,j]

Safety Algorithm 1) Let Work and Finish be vectors of length m and n rsply: initialize Work=Available and Finish=false 2) Find a I such that both Finish_I=false and Need_I<Work. If no such I exists go to step 4. 3) Work=Work+Allocation_I; Finish=true; goto step 2. 4) If Finish_I is true for all I, then the system is in a safe state., 1) Let Work and Finish be vectors of length m and n rsply: initialize Work=Available and Finish=false 2) Find a I such that both Finish_I=false and Need_I<Work. If no such I exists go to step 4. 3) Work=Work+Allocation_I; Finish=true; goto step 2. 4) If Finish_I is true for all I, then the system is in a safe state.,

Resource-Request Algorithm for Process P_i 1. If Request_I <= Need_I goto step 2. Otherwise error condition. 2. If Request_I <= Available, goto step 3. Otherwise,P_I must wait. 3. Pretend to allocate requested resource by modifying the state.Available=Available-Request_I; Allocation_i=Allocation_I+Request_I; Need_I=Need_I-Request_I; If Safe requests are allocated else P_I waits. 1. If Request_I <= Need_I goto step 2. Otherwise error condition. 2. If Request_I <= Available, goto step 3. Otherwise,P_I must wait. 3. Pretend to allocate requested resource by modifying the state.Available=Available-Request_I; Allocation_i=Allocation_I+Request_I; Need_I=Need_I-Request_I; If Safe requests are allocated else P_I waits.

Example 5 processes P0 to P4; 3 Resource types A (10 instances), B(5 instances) and C(7 instances) Snap slot at time T0 AllocationMaxAvailable A B CA B CA B C processes P0 to P4; 3 Resource types A (10 instances), B(5 instances) and C(7 instances) Snap slot at time T0 AllocationMaxAvailable A B CA B CA B C

Example P1 Requests (1,0,2) Can a request of (3,3,0) of P4 be granted Cana request (0,2,0) by P0 be granted. P1 Requests (1,0,2) Can a request of (3,3,0) of P4 be granted Cana request (0,2,0) by P0 be granted.

Deadlock Detection Allow system to enter deadlock state. Detection Algorithm Recovery scheme Allow system to enter deadlock state. Detection Algorithm Recovery scheme

Single Instance of Resource Type Maintain wait-for graph (nodes are processes, An edge Pi to Pj denotes that Pi is waiting for Pj). Periodically invoke an algorithm for finding cycle. Maintain wait-for graph (nodes are processes, An edge Pi to Pj denotes that Pi is waiting for Pj). Periodically invoke an algorithm for finding cycle.

Multiple Instances of Resource Type Data Structures Available, Allocation and Request as for Banker’s Algorithm Algorithm: 1) Let Work and Finish be vectors of length m and n resply. Initialize: Work=Available. If Allocation_I <>) then Finish_I=false else Finish_I=true; 2) Find an index I such that Finish[I]=false and Request[I]<=Work - if no such I exists goto 4. Data Structures Available, Allocation and Request as for Banker’s Algorithm Algorithm: 1) Let Work and Finish be vectors of length m and n resply. Initialize: Work=Available. If Allocation_I <>) then Finish_I=false else Finish_I=true; 2) Find an index I such that Finish[I]=false and Request[I]<=Work - if no such I exists goto 4.

Multiple Instances of Resource Type 3) Work=Work+Allocation Finsih[I]=true; goto step 2. 4) If Finish[I=false for some I, then the system is in a deadlock state. Moreover, if Finish[I]=false, then Pi is deadlocked. 3) Work=Work+Allocation Finsih[I]=true; goto step 2. 4) If Finish[I=false for some I, then the system is in a deadlock state. Moreover, if Finish[I]=false, then Pi is deadlocked.

Example 5 Processes three resource types A(&),B(2) and C (6). Snapshot at t0. AllocationRequestAvailable A B CA B CA B C Processes three resource types A(&),B(2) and C (6). Snapshot at t0. AllocationRequestAvailable A B CA B CA B C

Detection Algorithm Usage When and how to invoke depends on how often a deadlock is likely to occur and how many processes will be needed to rollback We also have to know which processes caused deadlock When and how to invoke depends on how often a deadlock is likely to occur and how many processes will be needed to rollback We also have to know which processes caused deadlock

Recovery from Deadlock Abort all processes Abort one process at a time until the deadlock cycle is eliminated. Which process to abort - priority, how long computation has been done, resources, interactive or batch Abort all processes Abort one process at a time until the deadlock cycle is eliminated. Which process to abort - priority, how long computation has been done, resources, interactive or batch

Recovery from Deadlock Selecting a victim - minimize cost Rollback - return to safe state. Starvation Selecting a victim - minimize cost Rollback - return to safe state. Starvation

Combined Approach to Deadlock Handling Combine the three basic approaches - Prevention, Avoidance and detection Partition the resources into hierarchically ordered classes Use most appropriate technique for handling deadlocks within each class. Combine the three basic approaches - Prevention, Avoidance and detection Partition the resources into hierarchically ordered classes Use most appropriate technique for handling deadlocks within each class.