Deadlock 1 Chapter 6

Similar documents
Deadlock 1 Chapter 6

ECE519 Advanced Operating Systems

Chapter 6 Concurrency: Deadlock and Starvation

CSE 306/506 Operating Systems Deadlock. YoungMin Kwon

Chapter 3. Deadlocks

Concurrency: Deadlock and Starvation. Chapter 6

Resources. Lecture 4. Deadlocks. Resources (2) Resources (1) Four Conditions for Deadlock. Introduction to Deadlocks

Chapter 3. Deadlocks

What is Deadlock? Two or more entities need a resource to make progress, but will never get that resource. Examples from everyday life:

Deadlock. Concurrency: Deadlock and Starvation. Reusable Resources

Deadlocks Prof. James L. Frankel Harvard University. Version of 7:05 PM 7-Mar-2017 Copyright 2017, 2015 James L. Frankel. All rights reserved.

DEADLOCKS M O D E R N O P E R A T I N G S Y S T E M S C H A P T E R 6 S P R I N G

What is the Race Condition? And what is its solution? What is a critical section? And what is the critical section problem?

Deadlocks. Thomas Plagemann. With slides from C. Griwodz, K. Li, A. Tanenbaum and M. van Steen

Chapter 6. Deadlocks

Operating Systems: William Stallings. Starvation. Patricia Roy Manatee Community College, Venice, FL 2008, Prentice Hall

Shared and Preemptable Resources. A few resources may be sharable. Anyone can write the system log.

OPERATING SYSTEMS. Deadlocks

Chapter 3: Deadlocks

CS450/550 Operating Systems

Deadlocks. Today. Next Time. ! Resources & deadlocks! Dealing with deadlocks! Other issues. ! Memory management

OPERATING SYSTEMS. Prescribed Text Book. Operating System Principles, Seventh Edition. Abraham Silberschatz, Peter Baer Galvin and Greg Gagne

Fig Bridge crossing - deadlock

Chapter 6 Concurrency: Deadlock and Starvation

Chapter 7: Deadlocks. Operating System Concepts 8th Edition, modified by Stewart Weiss

Resources. Chapter 3. Deadlocks. Resources. Resources

Deadlocks. Operating System Concepts - 7 th Edition, Feb 14, 2005

CSCC 69H3 2/1/13. Today: Deadlock. Remember example from last week? Example of Deadlock. Example: dining philosophers: Not just an OS Problem!

UNIT:2. Process Management

Learning Outcomes. Chapter 3. Deadlocks. Resources. Resources. Resources

VI. Deadlocks. What is a Deadlock? Intended Schedule. Deadlock Problem (1) ???

VI. Deadlocks Operating Systems Prof. Dr. Marc H. Scholl DBIS U KN Summer Term

Deadlocks. Today. Next Time. Resources & deadlocks Dealing with deadlocks Other issues. I/O and file systems

Deadlocks. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Concurrency: Deadlock and Starvation. Chapter 6

Introduction to OS. Deadlock. MOS Ch. 6. Mahmoud El-Gayyar. Mahmoud El-Gayyar / Introduction to OS 1

Deadlocks. Tore Larsen. With slides from T. Plagemann, C. Griwodz, K. Li, A. Tanenbaum and M. van Steen

Operating Systems. Deadlock. User OS. Kernel & Device Drivers. Interface Programs. Brian Mitchell - Operating Systems

Process Management. Deadlock. Process Synchronization. Management Management. Starvation

Deadlock and Starvation

Operating Systems ECE344. Ding Yuan

Learning Outcomes. Chapter 6. Deadlocks. Resources. Resources & Deadlocks. Resource Access. Two example resource usage patterns

Deadlocks. Dr. Yingwu Zhu

Operating Systems. Lecture3.2 - Deadlock Management. Golestan University. Hossein Momeni

COMPUTER SCIENCE 4500 OPERATING SYSTEMS

Deadlocks. Copyright : University of Illinois CS 241 Staff 1

Computer Science 4500 Operating Systems. In This Module. Deadlock Definition. Module 7 Deadlocks

Computer Science 4500 Operating Systems

! What is a deadlock? ! What causes a deadlock? ! How do you deal with (potential) deadlocks? Maria Hybinette, UGA

More on Synchronization and Deadlock

Operating System: Chap7 Deadlocks. National Tsing-Hua University 2016, Fall Semester

!! What is a deadlock? !! What causes a deadlock? !! How do you deal with (potential) deadlocks? Maria Hybinette, UGA

11 Resource Management Deadlock and Starvation

Deadlock. Rab Nawaz Jadoon DCS. Assistant Professor COMSATS Lahore Pakistan. Department of Computer Science

Deadlock. A Bit More on Synchronization. The Deadlock Problem. Deadlock Characterization. Operating Systems 2/7/2005. CSC 256/456 - Spring

The Slide does not contain all the information and cannot be treated as a study material for Operating System. Please refer the text book for exams.

Concurrency: Deadlock and Starvation

COP 4610: Introduction to Operating Systems (Spring 2016) Chapter 7 Deadlocks. Zhi Wang Florida State University

Deadlocks. Prepared By: Kaushik Vaghani

CMSC 412. Announcements

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.

Basics of Deadlock Theory. Deadlocks

CS420: Operating Systems. Deadlocks & Deadlock Prevention

Deadlock. Chapter Objectives

Chapter - 4. Deadlocks Important Questions

Operating Systems CMPSC 473. Deadlocks February 28, Lecture 13 Instructor: Trent Jaeger

Operating systems. Lecture 5. Deadlock: System Model. Deadlock: System Model. Process synchronization Deadlocks. Deadlock: System Model

Deadlock and Starvation

Module 6: Deadlocks. Reading: Chapter 7

Operating Systems. Operating Systems Sina Meraji U of T

DUH! Deadlocks. Concurrency Issues. The TENEX Case. If a process requests all systems buffers, operator console tries to print an error message

ICS Principles of Operating Systems. Lectures Set 5- Deadlocks Prof. Nalini Venkatasubramanian

System Model. Types of resources Reusable Resources Consumable Resources

Chapter 7: Deadlocks. Operating System Concepts 8 th Edition,

Deadlock and Starvation

Last Class: Monitors. Real-world Examples

MODERN OPERATING SYSTEMS. Third Edition ANDREW S. TANENBAUM. Chapter 6 Deadlocks

Deadlocks. Mehdi Kargahi School of ECE University of Tehran Spring 2008

Chapter 7: Deadlocks. Operating System Concepts 9th Edition DM510-14

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

Chapter 7: Deadlocks

Resource Management and Deadlocks 1

UNIT 4 DEADLOCKS 4.0 INTRODUCTION

CSE 380 Computer Operating Systems

Chapter 7: Deadlocks

Deadlock. Concepts to discuss. A System Model. Deadlock Characterization. Deadlock: Dining-Philosophers Example. Deadlock: Bridge Crossing Example

Final Exam Review. CPSC 457, Spring 2016 June 29-30, M. Reza Zakerinasab Department of Computer Science, University of Calgary

Operating Systems. Deadlock. Lecturer: William Fornaciari Politecnico di Milano Homel.deib.polimi.

The Deadlock Problem

Operating Systems. Designed and Presented by Dr. Ayman Elshenawy Elsefy

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

Chapter 7: Deadlocks. Operating System Concepts 8 th Edition,! Silberschatz, Galvin and Gagne 2009!

Contents. Chapter 8 Deadlocks

6. Concurrency: Deadlock

Chapters 5 and 6 Concurrency

Basic concepts and Terminologies

UNIT-5 Q1. What is deadlock problem? Explain the system model of deadlock.

The Deadlock Problem (1)

Chapter 8: Deadlocks. The Deadlock Problem

The Deadlock Problem. Chapter 8: Deadlocks. Bridge Crossing Example. System Model. Deadlock Characterization. Resource-Allocation Graph

Transcription:

Deadlock 1 Chapter 6

2 Deadlock A set of processes is deadlocked when each process in the set is blocked awaiting an event that can only be triggered by another blocked process in the set Permanent blocking of a set of processes that either compete for system resources or communicate with each other Involves conflicting needs for resources by two or more processes Bad news: There is no satisfactory solution in the general case

3 Example: Potential Deadlock

4 Example: Potential Deadlock

5 Joint Progress Diagram How to intuitively observe a deadlock? A solution is to use the joint progress diagram Shows all possibilities of process progresses with time (i.e., sequence of interleaved instructions) E.g.: Two processes P and Q need to exclusively access resources A and B for a period of time

6 Joint Progress Diagram

7 Joint Progress Diagram Consider an alternative sequence that that P does not need both resources at the same

8 Joint Progress Diagram

9 Resource Allocation Graph Directed graph that depicts a state of the system of resources and processes Process is represented by circle Resource is represented by square

10 Resource Allocation Graph

11 Example of Resource Allocation Graphs

12 Four Conditions for Deadlock Mutual exclusion Only one process may use a resource at a time Hold-and-wait A process may hold allocated resources while awaiting assignment of others No preemption No resource can be forcibly removed from a process holding it Circular wait A closed chain of processes exists, such that each process holds at least one resource needed by the next process in the chain

13 Four Conditions for Deadlock Deadlock occurs if and only if the circular wait condition is unresolvable The circular wait condition is unresolvable when the first 3 policy conditions hold Thus the 4 conditions taken together constitute necessary and sufficient conditions for deadlock

14

15

16 Dealing with Deadlock Three general approaches exist for dealing with deadlock Prevent deadlock: disallow 1 of the 4 necessary conditions of deadlock occurrence Avoid deadlock: do not grant a resource request if this allocation might lead to deadlock Detect deadlock: always grant resource request when possible, but periodically check for the presence of deadlock and then recover from it

17 Deadlock Prevention Idea: invalidate one of the four conditions for deadlock Mutual exclusion Hold-and-wait No preemption Circular wait Indirect methods: attacking the first three conditions Direct methods: attacking the last condition (e.g., circular wait)

18 Attacking Mutual Exclusion Some devices (such as printer) can be spooled Only the printer daemon uses printer resource Thus deadlock for printer eliminated In general, we cannot (or don t want to remove mutual exclusion), and not all devices can be spooled Principle Avoid assigning resource when not absolutely necessary (e.g., consider how mutex lock for critical sessions) As few processes as possible actually claim the resource

19 Attacking Hold and Wait Require processes to request and get all resources before starting A process never has to wait for what it needs Problems May not know required resources at start of run May wait for long to acquire all resources Ties up resources other process could be using Variation: before requesting a new resource Process must give up all previous resources Then request all immediately need resources

20 Attacking No Preemption As we have discussed, disabling preemption is not a viable option Consider a process given the printer Halfway through it job of printing a page Now forcibly take away the printer No a solution!!

21 Attacking Circular Wait There is a solution to attack circular wait: Every resource has a unique number A process must request resources in an increasing number order For example: A process initially request a Ri with an index O(Ri) After that, the process can request another resource Rj if and only if O(Rj) > O(Ri)

22 Attacking Circular Wait Circular wait cannot hold under this protocol. Proof: Processes {P0, P1..Pn} are involved in circular wait iff Pi is waiting for Ri which is held by Pi+1 and Pn is waiting for Rn held which is held by P0 (circular waiting) under this protocol, this means: O(R0) < O(R1) <.. < O(Rn) < O(R0) impossible! This protocol prevents deadlock but will often deny resources unnecessarily (inefficient) because of the ordering imposed on the requests

23 Deadlock Avoidance A decision is made dynamically whether the current resource allocation requires will, if granted, potentially lead to a deadlock Allows more concurrency than prevention, but require knowledge of future process requests Two approaches: Process Initiation Denial: do not start a process if it s demand might lead to deadlock Resource Allocation Denial: do not grant an incremental resource request if this allocation might lead to deadlock In both cases: maximum requirements of each resource must be stated in advance

24 Resource types Resources in a system are partitioned in resources types Each resource type in a system exists with a certain amount. Let R(i) be the total amount of resource type i present in the system. E.g.: R(main memory) = 128 MB R(disk drives) = 8 R(printers) = 5 The partition is system specific (e.g.: disk drives may be further partitioned...)

25 Process Initiation Denial Let C(k,i) be the amount of resource type i claimed by process k. To be admitted in the system, process k must show C(k,i) for all resource types i C(k,i) is the maximum value of resource type i permitted for process k. Let U(i) be the total amount of resource type i unclaimed or available in the system: U(i) = R(i) - S_k C(k,i)

26 Process Initiation Denial A new process n is admitted in the system only if C(n,i) <= U(i) for all resource type i This policy ensures that deadlock is always avoided since a process is admitted only if all its requests can always be satisfied (no matter what will be their order) Not optimal since it assumes the worst: that all processes will make their maximum claims together at the same time

27 Resource Allocation Denial: the Banker s Algorithm Metaphor: processes are like customers wanting to borrow money (resources) from a bank... A banker should not allocate cash when it cannot satisfy all the (future) needs of a customer, constrained by other customers Consider a system with fixed number of resources State of the system is the current allocation of resources to processes (i.e., encoded by R(i), C(j,i), and others) Safe state is where there is at least one sequence that does not result in deadlock Unsafe state is the state that is not safe

28 The Banker s Algorithm We also need the amount of resource type i that are allocated to process j for all (j,i), denoted as A(j,i) The total amount of available resource for each type i is defined by V(i) that satisfies V(i) = R(i) - S_k A(k,i) We also use an intermediate variable need N(j,i) of resource type i required by process j to complete its task: N(j,i) = C(j,i) - A(j,i) To decide if a resource request made by a process should be granted, the banker s algorithm test if granting the request will lead to a safe state, by testing C(j,i) - A(j,i) <= V(i) If the resulting state is safe then grant request; else do not grant the request

29 The Banker s Algorithm m is the number of resource types n is the number of processes

30 The Banker s Algorithm The banker s algorithm is all about the determination of a safe state For example: a system consisting of 4 process and 3 resource types with the following configuration at a time point, is this a safe state? Note: These two are usually unknown and must be computed from others

31 The Banker s Algorithm We need to check C(j,i) - A(j,i) <= V(i) for all j For P1 (i.e., j=1), this is not possible for P1 Which requests 2 units of R1, but no R1 is available Similarly, the system doesn t have sufficient R2 and R3 for P1 Note: These two are usually unknown and must be computed from others

32 The Banker s Algorithm We need to check C(j,i) - A(j,i) <= V(i) for all j For P2, if we assign 1 unit of R3 to P2 Then P2 has its maximum required resources allocated and can run to completion Note: These two are usually unknown and must be computed from others

33 The Banker s Algorithm We need to check C(j,i) - A(j,i) <= V(i) for all j For P2, if we assign 1 unit of R3 to P2 Then P2 has its maximum required resources allocated and can run to completion And it will return resources to the available pool Note: P2 is completed Note: These two are usually unknown and must be computed from others

34 The Banker s Algorithm We need to check C(j,i) - A(j,i) <= V(i) for all j After P2 runs to completion, can any of the remaining processes can be completed? Start over the checking again (from the beginning by convention) Yes, now the available resources are sufficient for P1 Note: P2 is completed Note: These two are usually unknown and must be computed from others

35 The Banker s Algorithm We need to check C(j,i) - A(j,i) <= V(i) for all j After P1 completes: The system has more resources, which are sufficient for both P3 and P4 By convention, we check from the beginning of the process list, and P3 will start before P4

36 The Banker s Algorithm After P3 completes: The system has even more resources, which can be all allocated to P4 Thus, the state defined originally is a safe state

37 The Banker s Algorithm If we accidently give P1 one additional unit of R1 and R3, is this new state safe? Thus, this new state is unsafe

38 Banker s Algorithm: Comments Pros: It is not necessary to preempt and rollback processes, as in deadlock detection It is less restrictive than deadlock prevention Cons: Maximum resource requirement must be stated in advance Processes under consideration must be independent and with no synchronization requirements There must be a fixed number of resources to allocate No process may exit while holding resources

39 Deadlock Detection Deadlock prevention strategies are very conservative Limit access to resources and impose restrictions on processes during the system design Deadlock detection strategies do the opposite Resource requests are granted whenever possible Regularly check for deadlock

40 Deadlock Recovery Needed when deadlock is detected. The following methods are possible: Abort all deadlocked processes (one of the most common solution adopted in OS!!) Rollback each deadlocked process to some previously defined checkpoint and restart them (original deadlock may reoccur) Successively abort deadlock processes until deadlock no longer exists Successively preempt resources until deadlock no longer exists