Lecture 7: Deadlock     Necessary Conditions for Deadlock     Deadlock Prevention - Havender's Linear Ordering Deadlock Avoidance Deadlock Detection &

Slides:



Advertisements
Similar presentations
Lecture 8 Restrictions on Resource Allocation Dining Philosophers - Havender's Linear Ordering.
Advertisements

Deadlock Prevention, Avoidance, and Detection
ICS Principles of Operating Systems Lectures 8 and 9 - Deadlocks Prof. Dmitri V. Kalashnikov dvk ics.uci.edu Slides © Prof. Nalini Venkatasubramanian.
Deadlock and Starvation
1 Deadlock Solutions: Avoidance, Detection, and Recovery CS 241 March 30, 2012 University of Illinois.
Concurrency: Deadlock and Starvation Chapter 6. Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate.
6. Deadlocks 6.1 Deadlocks with Reusable and Consumable Resources
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Chapter 6 Concurrency: Deadlock and Starvation
Chapter 6 Concurrency: Deadlock and Starvation
Chapter 81 Deadlock is:  A set of blocked processes each holding a resource and waiting to acquire a resource held by another process in the set.  Example.
Ceng Operating Systems Chapter 2.4 : Deadlocks Process concept  Process scheduling  Interprocess communication  Deadlocks Threads.
 2004 Deitel & Associates, Inc. All rights reserved. Chapter 7 – Deadlock and Indefinite Postponement Outline 7.1 Introduction 7.2Examples of Deadlock.
EEE 435 Principles of Operating Systems Deadlock Avoidance, Prevention, and Wrap-Up (Modern Operating Systems 3.5, 3.6, and 3.7)
7.4 Resource Concepts Preemptible resources (e.g. processors and main memory) –Can be removed from a process without loss of work Nonpreemptible resources.
Chapter 3 Deadlocks TOPICS Resource Deadlocks The ostrich algorithm
Operating Systems 6. Deadlock (Ch. 7, S&G) Objectives
Deadlock Chapter 3 R1 R2 P2P1 Allocated Requested.
Chapter 6 Concurrency: Deadlock and Starvation
CSI 400/500 Operating Systems Spring 2009 Lecture #17 –Deadlocks Wednesday, April 15 th.
Deadlock CSCI 444/544 Operating Systems Fall 2008.
Concurrency: Deadlock & Starvation
CS 450 OPERATING SYSTEMS DEADLOCKS Manju Muralidharan Priya.
The ‘deadlock’ conditions Reviewing some key points concerning the potential for ‘deadlock’ in an operating system.
OS Spring 2004 Concurrency: Principles of Deadlock Operating Systems Spring 2004.
OS Fall’02 Concurrency: Principles of Deadlock Operating Systems Fall 2002.
Chapter 6 Concurrency: Deadlock and Starvation
7: Deadlocks1 DEADLOCKS EXAMPLES: "It takes money to make money". You can't get a job without experience; you can't get experience without a job. BACKGROUND:
Deadlock Characterization
Concurrency: Deadlock and Starvation Chapter 6. Goal and approach Deadlock and starvation Underlying principles Solutions? –Prevention –Detection –Avoidance.
Operating Systems (OS)
CS6502 Operating Systems - Dr. J. Garrido Deadlock – Part 2 (Lecture 7a) CS5002 Operating Systems Dr. Jose M. Garrido.
CIS Operating Systems Deadlock Professor Qiang Zeng Fall 2015.
Resource Management Reusable  Disk blocks  File descriptors  Semaphores Consumable  Messages  Packets.
Operating System Concepts and Techniques Lecture 15 Deadlock and starvation-1 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques,
Chapter 6 Concurrency: Deadlock and Starvation
Lecture 12 Handling Deadlock – Prevention, avoidance and detection.
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings.
Chapter 5 Process Management Semester 2. Objectives  What is a deadlock?  Seven cases of deadlocks  Conditions of deadlocks –Mutual exclusion.
Deadlocks Copyright ©: University of Illinois CS 241 Staff1.
Silberschatz, Galvin and Gagne ©2009 Edited by Khoury, 2015 Operating System Concepts – 9 th Edition, Chapter 7: Deadlocks.
Copyright ©: Nahrstedt, Angrave, Abdelzaher1 Deadlock.
Informationsteknologi Monday, October 1, 2007Computer Systems/Operating Systems - Class 111 Today’s class Deadlock.
Deadlocks References –text: Tanenbaum ch.3. Deadly Embrace Deadlock definition –A set of process is dead locked if each process in the set is waiting.
Deadlocks CPE Operating Systems
Process Management Deadlocks.
CSE 120 Principles of Operating
Operating Systems, Summer Semester 2011
Operating Systems, Winter Semester 2011
ITEC 202 Operating Systems
Chapter 7 – Deadlock and Indefinite Postponement
Chapter 6 : Deadlocks What is a Deadlock?
Deadlocks References text: Tanenbaum ch.3.
Chapter 7 Deadlock.
Lecture 19: Deadlock: Conditions, Detection and Avoidance
Deadlock avoidance Deadlock detection Resource Allocation Graphs
Deadlocks References text: Tanenbaum ch.3.
Deadlocks Definition A set of processes is in a Deadlock state when every process in the set is waiting for an event that can only be caused by another.
Banker`s Algorithm Developed by Dijkstra in 1965
Deadlocks Peng Lu In a multiprogramming environment, several processes may compete for a finite number of resources. A process requests resources; if the.
The relation between the process and
DEADLOCK.
Lecture 27 Syed Mansoor Sarwar
Lecture 19: Deadlock: Conditions, Detection and Avoidance
Operating System 6 CONCURRENCY: MUTUAL EXCLUSION AND SYNCHRONIZATION
OPERATING SYSTEMS DEADLOCKS.
DEADLOCKS.
Deadlocks References text: Tanenbaum ch.3.
Presentation transcript:

Lecture 7: Deadlock     Necessary Conditions for Deadlock     Deadlock Prevention - Havender's Linear Ordering Deadlock Avoidance Deadlock Detection & Recovery Resource Allocation Graphs

Examples of Deadlock Deadlock occurs with two or more processes are waiting for system conditions that will never occur. In a typical deadlock state there are processes holding some resource while waiting for other resources to become available. Resource 1 Process A B 2 In a resource allocation diagram, an arrow from a resource to a process means that this resource is allocated to the process. An arrow from a process to a resource means that this process is requesting the resource. The diagram shows a simple case of deadlock between the two processes. Each process is holding a resource and requesting the other.

Four Necessary Conditions for Deadlock 1. mutual exclusion - processes claim exclusive control of the resources they require. 2. wait for - processes hold resource already allocated to them while waiting for additional resources. 3. no preemption - resources cannot be removed from the processes holding them until the resources are used to completion. 4. circular wait - a circular chain of processes exists in which each process holds one or more resources that are requested by the next process in the chain.

Deadlock Prevention Deadlock can be prevented by denying one of the four necessary contitions for deadlock to occur. This is called deadlock prevention. Since we must enforce mutual exclusion there are three general approaches for deadlock prevention, suggested by Havender. denying wait-for - each process must request all it required resource at once and cannot proceed until all have been granted. deny no-preemption - if a process holding certain resource is denied a further request, that process must release its original resources and, if necessary, requiest them again together with the additinal resources. deny circular wait - impose a linear ordering of resource types on all processes; i.e., if a process has been allocated resources of a given type, it may subsequently request only those resources of types later in the ordering.

Havender's Linear Ordering The linear-ordering strategy denies the possibility of circular wait in the following manner. Each resource type is labeled with a value with those resource commonly needed at the beginning of a tasks having lower values than those that typically come at the end of a task. A process may request and hold resources in an ascending orderonly. This means that a process may not request any resource of a lower value (ordering value) so long as any resources of a higher value are being held. For example, while process P1 has possession of R4 it may not request an R3 or an R2. Discuss how a process that needs an R1 resource both early and late in its operations can accomplish this. R6 P2 P1 R5 R4 P2 R3 P1 P2 R2 R1

Deadlock Avoidance Sometimes it is not feasible to prevent deadlock. This can occur when we need the most effective use of all our resources. Instead of denying one of the four necessary conditions for deadlock we can monitor resource allocation and avoid the situations in which deadlock might occur (unsate state).Dijkstra has developed the Banker's Algorithm which avoids unsafe states. A Safe State Current Aloc Max Need User(1) 1 4 User(2) 4 6 User(3) 5 8 Avail 2 An Unsafe State Current Aloc Max Need User(1) 1 4 User(2) 4 6 User(3) 6 8 Avail 1

Deadlock Detection P1 P2 P3 In some systems the OS allows deadlock to occur and then suspends or restarts the deadlocked processes allowing others to proceed. To accomplish this recovery we must first have a means of detecting deadlock. Remember that all processes running in a multiprogramming environment need not be involved in the deadlock. Resource allocation diagrams are a graphical representation of an algorithm for deadlock detection. Each resource type is shown as a large circle, each instance of a resource is shown as a smaller circle in one of the large circles. Each process is shown as a rectangle. When a resource is allocated to a process an arrow is drawn from the resource instance to the process. When a process requests a resource an arrow is drawn from the process to the desired resource type. R1 R2 P1 P2 P3

Deadlock Detection by Graph Resolution Deadlock can be detected by reducing resource allocation graphs. Follow the algorithm described below to find the processes involved in deadlock: 1. Build a complete graph. 2. Remove any processes that have all their resources. 3. Return all released resources to the pool of available resources. 4. Satisfy waiting resource requests with newly released resources. 5. Repeat Steps 2,3 and 4 (with back- tracking if necessary) until all processes are removed or until no more requests can be satisfied. 6. Remaining processes are suspended one-at-a-time until deadlock is eliminated. Is there a way to avoid the deadlock shown in Step D? A B C D

Using Resource Allocation Graphs to Prevent Deadlock Consider a special case of resource allocation graphs in which you require that each resource type contains no more than one more resource that any other resource type and that a process may request at most one resource of each type. Given 3 resource types (R), and 2 processes (P) what is the total number of resources N (evenly disributed among the 3 resource types) needed to prevent the possibility of deadlock? R1 R2 R3 Develop an expression for the total number of resources N needed to be distributed evenly across R resource types to prevent deadlock in P processes (again assume that each process can request at most 1 of each resource type). P1 P2

Banker’s Algorithm A Sample Problem A system that uses Banker’s Algorithm deadlock avoidance has five processes and uses resorces of four different types. There are multiple resources of each type. Is the state of the system as shown below safe? Explain your answer. If the system is safe, show how all the processes could complete their execution successfully. If the system is unsafe, show how deadlock might occur. (textbook p. 178, prob. 6.34) Total Resources Resources Available A B C D A B C D 13 13 9 13 3 4 0 1 Current Maximum Current Process loan need request A B C D A B C D A B C D 1 1 0 2 0 3 2 4 2 2 2 2 2 2 0 3 1 2 3 5 1 2 3 2 0 0 3 2 4 5 1 2 7 7 5 0 3 2 4 4 3 0 0 6 5 5 0 8 2 5 0 2 5 4 2 1 3 6 2 1 4 2 0 0 1 The current claim (request) is given as the maximum allowed for each process and resource type.

Dining Philosophers P0 P1 P2 P3 P4 R0 R4 R1 R3 R2

Summary Examples of Deadlock Four Necessary Conditions (1) mutual exclusion ( 2) wait-for (3) no preemption (4) circular wait Deadlock Prevention requires denial of one of the four necessary conditions Deadlock Avoidance (Safe State) allows the possibility of deadlock Deadlock Detection is not always simple Restrictions on Resource Allocation (preventing or avoiding deadlock?) Dining Philosophers How many different resources? How to represent Resource Allocation Graph How to implement Havender's Linear Ordering