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

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

CISC 7310X. C10: Deadlocks. Hui Chen Department of Computer & Information Science CUNY Brooklyn College. 4/12/2018 CUNY Brooklyn College

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

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

Chapter 3. Deadlocks

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

Chapter 6. Deadlocks

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

Chapter 3. Deadlocks

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

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

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

Chapter 3: Deadlocks

OPERATING SYSTEMS. After A.S.Tanenbaum, Modern Operating Systems, 3rd edition. Uses content with permission from Assoc. Prof. Florin Fortis, PhD

Resources. Chapter 3. Deadlocks. Resources. Resources

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

Operating Systems. Deadlocks

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

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

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

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

Chapter 6 - Deadlocks

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

Concurrency problems. To do. q Non-deadlock bugs q Resources & deadlocks q Dealing with deadlocks q Other issues q Next Time: I/O and file systems

COMPUTER SCIENCE 4500 OPERATING SYSTEMS

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

Computer Science 4500 Operating Systems

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

Chapter 8: Deadlocks. Bridge Crossing Example. The Deadlock Problem

Concurrency problems. q Non-deadlock bugs q Resources & deadlocks q Dealing with deadlocks q Other issues q Next Time: I/O and file systems

CSE 306/506 Operating Systems Deadlock. YoungMin Kwon

Operating Systems Structure

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.

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

CS450/550 Operating Systems

Back to synchronization

More on Synchronization and Deadlock

Chapter 6. Deadlock. (A Quick Introduction)

Administrivia. Assignments 0 & 1 Class contact for the next two weeks Next week. Following week

Yet another synchronization problem

6. Concurrency: Deadlock

Process P holds resource R. Process P is waiting for resource R. P Process P holds T and requests R. R Process Q holds R and requests T

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

Deadlocks. Operating Systems. Resources. Deadlocks

Operating Systems ECE344. Ding Yuan

Lecture 7 Deadlocks (chapter 7)

CSE 380 Computer Operating Systems

Deadlocks. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Outline. Deadlock. Examples, Conditions, Strategies. Deadlock Prevention. Deadlock Avoidance. Banker s algorithm

CSE Opera+ng System Principles

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

Deadlocks. Dr. Yingwu Zhu

We need a formal algorithm, as visual inspection is not sufficient Many algorithms for detecting cycles in a directed graph are known o Below is a

CMSC 412. Announcements

Chapter 3: Deadlocks. Chapter 3

Bridge Crossing Example

Chapter 7: Deadlocks

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

Chapter 8: Deadlocks. The Deadlock Problem

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

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

The Deadlock Problem

Chapter 7: Deadlocks

Chapter 8: Deadlocks

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

The Deadlock Problem

The Deadlock Problem

Introduction to Deadlocks

Module 7: Deadlocks. The Deadlock Problem. Bridge Crossing Example. System Model

Deadlock. Concurrency: Deadlock and Starvation. Reusable Resources

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

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

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

Deadlock and Starvation

Deadlock Prevention. Restrain the ways request can be made. Mutual Exclusion not required for sharable resources; must hold for nonsharable resources.

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

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

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

Deadlock and Starvation

Chapter 7: Deadlocks. Chapter 7: Deadlocks. The Deadlock Problem. Chapter Objectives. System Model. Bridge Crossing Example

Last Class: Monitors. Real-world Examples

Readings and References. Deadlock. Deadlock. Simple Traffic Gridlock Example. Reading. CSE Computer Systems November 30, 2001.

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

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

COMP 346 WINTER Tutorial 9 DEADLOCK

Module 7: Deadlocks. The Deadlock Problem

Chapter 8: Deadlocks. The Deadlock Problem

Module 7: Deadlocks. System Model. Deadlock Characterization. Methods for Handling Deadlocks. Deadlock Prevention. Deadlock Avoidance

Operating Systems 2006/2007

Deadlocks. Minsoo Ryu. Real-Time Computing and Communications Lab. Hanyang University.

Chapter 7: Deadlocks

The Deadlock Problem (1)

Chapter 7: Deadlocks

Contents. Chapter 8 Deadlocks

Frequently asked questions from the previous class survey

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

Principles of Operating Systems

Deadlock. Disclaimer: some slides are adopted from Dr. Kulkarni s and book authors slides with permission 1

Deadlock. Disclaimer: some slides are adopted from Dr. Kulkarni s and book authors slides with permission 1

Transcription:

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

Preemptable and Nonpreemptable Resources Sequence of events required to use a resource: 1. Request the resource. 2. Use the resource. 3. Release the resource.

Resource Acquisition (1) Figure 6-1. Using a semaphore to protect resources. (a) One resource. (b) Two resources.

Resource Acquisition (2) Figure 6-2. (a) Deadlock-free code.

Resource Acquisition (3) Figure 6-2. (b) Code with a potential deadlock.

Introduction To Deadlocks Deadlock can be defined formally as follows: A set of processes is deadlocked if each process in the set is waiting for an event that only another process in the set can cause.

Conditions for Resource Deadlocks 1. Mutual exclusion condition 2. Hold and wait condition. 3. No preemption condition. 4. Circular wait condition.

Deadlock Modeling (1) Figure 6-3. Resource allocation graphs. (a) Holding a resource. (b) Requesting a resource. (c) Deadlock.

Deadlock Modeling (2) Figure 6-4. An example of how deadlock occurs and how it can be avoided.

Deadlock Modeling (3) Figure 6-4. An example of how deadlock occurs and how it can be avoided.

Deadlock Modeling (4) Figure 6-4. An example of how deadlock occurs and how it can be avoided.

Deadlock Modeling (5) Strategies for dealing with deadlocks: 1. Just ignore the problem. 2. Detection and recovery. Let deadlocks occur, detect them, take action. 3. Dynamic avoidance by careful resource allocation. 4. Prevention, by structurally negating one of the four required conditions.

Deadlock Detection with One Resource of Each Type (1) Figure 6-5. (a) A resource graph. (b) A cycle extracted from (a).

Deadlock Detection with One Resource of Each Type (2) Algorithm for detecting deadlock: 1. For each node, N in the graph, perform the following five steps with N as the starting node. 2. Initialize L to the empty list, designate all arcs as unmarked. 3. Add current node to end of L, check to see if node now appears in L two times. If it does, graph contains a cycle (listed in L), algorithm terminates.

Deadlock Detection with One Resource of Each Type (3) 4. From given node, see if any unmarked outgoing arcs. If so, go to step 5; if not, go to step 6. 5. Pick an unmarked outgoing arc at random and mark it. Then follow it to the new current node and go to step 3. 6. If this is initial node, graph does not contain any cycles, algorithm terminates. Otherwise, dead end. Remove it, go back to previous node, make that one current node, go to step 3.

Deadlock Detection with Multiple Resources of Each Type (1) Figure 6-6. The four data structures needed by the deadlock detection algorithm.

Deadlock Detection with Multiple Resources of Each Type (2) Deadlock detection algorithm: 1. Look for an unmarked process, P i, for which the i-th row of R is less than or equal to A. 2. If such a process is found, add the i-th row of C to A, mark the process, and go back to step 1. 3. If no such process exists, the algorithm terminates.

Deadlock Detection with Multiple Resources of Each Type (3) Figure 6-7. An example for the deadlock detection algorithm.

Recovery from Deadlock Recovery through preemption Recovery through rollback Recovery through killing processes

Deadlock Avoidance Figure 6-8. Two process resource trajectories.

Safe and Unsafe States (1) Figure 6-9. Demonstration that the state in (a) is safe.

Safe and Unsafe States (2) Figure 6-10. Demonstration that the state in (b) is not safe.

The Banker s Algorithm for a Single Resource Figure 6-11. Three resource allocation states: (a) Safe. (b) Safe. (c) Unsafe.

The Banker s Algorithm for Multiple Resources (1) Figure 6-12. The banker s algorithm with multiple resources.

The Banker s Algorithm for Multiple Resources (2) Algorithm for checking to see if a state is safe: 1. Look for row, R, whose unmet resource needs all A. If no such row exists, system will eventually deadlock since no process can run to completion 2. Assume process of row chosen requests all resources it needs and finishes. Mark process as terminated, add all its resources to the A vector. 3. Repeat steps 1 and 2 until either all processes marked terminated (initial state was safe) or no process left whose resource needs can be met (there is a deadlock).

Deadlock Prevention Attacking the mutual exclusion condition Attacking the hold and wait condition Attacking the no preemption condition Attacking the circular wait condition

Attacking the Circular Wait Condition Figure 6-13. (a) Numerically ordered resources. (b) A resource graph.

Approaches to Deadlock Prevention Figure 6-14. Summary of approaches to deadlock prevention.

Other Issues Two-phase locking Communication deadlocks Livelock Starvation

Communication Deadlocks Figure 6-15. A resource deadlock in a network.

Livelock Figure 6-16. Busy waiting that can lead to livelock.