CSE 306/506 Operating Systems Deadlock. YoungMin Kwon

Similar documents
ECE519 Advanced Operating Systems

Chapter 6 Concurrency: Deadlock and Starvation

Deadlock. Concurrency: Deadlock and Starvation. Reusable Resources

Concurrency: Deadlock and Starvation

System Model. Types of resources Reusable Resources Consumable Resources

Concurrency: Deadlock and Starvation. Chapter 6

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

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

Concurrency Issues. Past lectures: What about coordinated access across multiple objects? Today s lecture:

Chapter - 4. Deadlocks Important Questions

Deadlock and Starvation

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

Deadlock 1 Chapter 6

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

Bridge Crossing Example

OPERATING SYSTEMS. Deadlocks

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

Deadlock and Starvation

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.

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

Module 6: Deadlocks. Reading: Chapter 7

Chapter 7: Deadlocks

Concurrency: Deadlock and Starvation. Chapter 6

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

Deadlock 1 Chapter 6

CSE Opera+ng System Principles

Chapter 6 Concurrency: Deadlock and Starvation

Chapter 7: Deadlocks

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

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

The Deadlock Problem

ECS 150 (Operating Systems) Goal To examine what causes deadlock, and what to do about it. Spring Quarter

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

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

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

Chapter 8: Deadlocks

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

Chapter 3. Deadlocks

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

Chapter 7: Deadlocks

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

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

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

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

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

The Deadlock Problem

Chapter 7: Deadlocks

Deadlock and Starvation

Chapter 3. Deadlocks

Lecture 7 Deadlocks (chapter 7)

Chapter 7: Deadlocks. Operating System Concepts with Java 8 th Edition

Concurrency: Principles of Deadlock. Processes and resources. Concurrency and deadlocks. Operating Systems Fall Processes need resources to run

Deadlocks. Deadlock Overview

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

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

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

Resource Management and Deadlocks 1

Chapter 8: Deadlocks. The Deadlock Problem

Principles of Operating Systems

CS307 Operating Systems Deadlocks

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

The Deadlock Problem (1)

Deadlocks. Dr. Yingwu Zhu

Deadlocks. Bridge Crossing Example. The Problem of Deadlock. Deadlock Characterization. Resource-Allocation Graph. System Model

Basic concepts and Terminologies

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

CMSC 412. Announcements

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

Deadlocks. Prepared By: Kaushik Vaghani

CSCE Operating Systems Deadlock. Qiang Zeng, Ph.D. Fall 2018

Roadmap. Deadlock Prevention. Deadlock Prevention (Cont.) Deadlock Detection. Exercise. Tevfik Koşar. CSE 421/521 - Operating Systems Fall 2012

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

Chapter 6. Deadlocks

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

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

CSE120 Principles of Operating Systems. Prof Yuanyuan (YY) Zhou Deadlock

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

Module 7: Deadlocks. The Deadlock Problem

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

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

CS307: Operating Systems

Chapters 5 and 6 Concurrency

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

COMP 346 WINTER Tutorial 9 DEADLOCK

The Deadlock Problem

Chapter 8: Deadlocks. Operating System Concepts with Java

Chapter 7: Deadlocks 1

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

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

Chapter 8: Deadlocks. The Deadlock Problem

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

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

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

Deadlocks. Operating Systems. Resources. Deadlocks

Basics of Deadlock Theory. 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.

Operating Systems ECE344. Ding Yuan

Deadlocks. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Last Class: Monitors. Real-world Examples

Principles of Operating Systems

Transcription:

CSE 306/506 Operating Systems Deadlock YoungMin Kwon

Deadlock A set of processes are deadlocked if Each process in the set is blocked and Waiting for an event that can be triggered only from another process in the set

Deadlock Illustration of deadlock a, b, c, d are resources and 1, 2, 3, 4 are processes

Joint Progress Diagram Illustrates the progress of two processes competing for resources The progress path moves only from left to right or from bottom to top Each process needs exclusive use of both resources Exclusive use forms prohibited regions in the diagram Deadlock occurs if the progress path cannot move

Joint Progress Diagram An example of deadlock Two processes P and Q acquire and release resources A and B in the following order

Joint Progress Diagram An example of NO deadlock Two processes P and Q acquire and release resources A and B in the following order

Resources Reusable resources Resources that can be used by a process at a time and not depleted by that use Processor, I/O channels, memory, device, and data structures (files, DB, semaphores) Deadlock example (200 KB of available memory)

Resources Consumable resources Resources that can be created and destroyed Interrupts, signals, messages, data in I/O buffers Deadlock example Each process tries to receive a message from the other

Resource Allocation Graph Resource allocation graph Directed graph that depicts the state of the resources and processes Nodes are processes and resources Resource request: the directed edge from the requesting process to the resource Granted resource: the directed edge from the resource to the process

Resource Allocation Graph Circular wait: deadlock No deadlock

Resource Allocation Graph

4 Conditions for Deadlock Mutual exclusion Only one process may use a resource at a time Hold and wait Processes make requests while holding resources No preemption Granted resources cannot be forcefully removed Circular wait A closed chain exists in the resource allocation graph

Deadlock Prevention Design a system such that the possibility of deadlock is statically excluded Preventing one of the 4 deadlock conditions Mutual exclusion In general, this condition cannot be disallowed

Deadlock Prevention Hold and wait Require processes to make request for all necessary resources together Inefficiency of hold and wait Processes may need to wait long when it can make progresses with some of the resources Resources may be held for a long time without being used

Deadlock Prevention No preemption Make processes release all resources held if a further request is denied Alternatively, resources held by a process are released if requested by other processes Works when no two processes have the same priority Need to save and restore process states

Deadlock Prevention Circular wait Define a linear order of resources If a process has a resource of order R, it can make requests only for resources of order R such that R > R Like the hold and wait prevention, circular waitprevention strategy can be inefficient Unnecessarily slowing down processes and denying resource access

Deadlock Avoidance More concurrency than the prevention strategies Allows the first three conditions Dynamically decide whether the current resource request, if granted, will potentially lead to a deadlock Two approaches Do not start a process if its demand may lead to a deadlock Do not grant a resource request if it may lead to a deadlock (Banker s algorithm)

Process Initiation Denial Consider a system of n processes and m types of resources Define two vectors R and V and two matrices C and A

Process Initiation Denial Relations among R, V, C, and A Deadlock avoidance policy

Banker s Algorithm A system state comprises R, V, C, and A Safe state There is a sequence of resource allocations that can make all processes run to complete (without deadlock) A process i can run to completion if Unsafe state A state that is not safe

Banker s Algorithm (Safe State?) Decide whether this initial state is safe P2 can run to complete

Banker s Algorithm (Safe State?) P2 is complete; fill the 2 nd row of C and A with 0 Update V with the resources held by P2 Now, P1 can run to complete

Banker s Algorithm (Safe State?) P1 is complete; fill the 1 st row of C and A with 0 Update V with the resources held by P1 P3 can run to complete

Banker s Algorithm (Safe State?) P3 is complete; fill the 3 rd row of C and A with 0 Update V with the resources held by P3 P4 can run to complete As all processes can run to complete the initial state is safe

Banker s Algorithm Banker s algorithm Grant resources only when the resulting state will be safe

Banker s Algorithm Example 1 Given the state, if P2 requests for 1 R1 and 1 R3

Banker s Algorithm Example 1 Above is the resulting state if the request is granted The resulting state is the same as the initial state of the previous example Grant the resources because the resulting state is safe

Banker s Algorithm Example 2 Given the state, if P1 requests for 1 R1 and 1 R3

Banker s Algorithm Example 2 Above is the resulting state if the request is granted This state is unsafe as no process can run to complete Thus, the request should not be granted

Deadlock Detection Deadlock detection strategy Do not limit resource requests Periodically check if there is a deadlock Assuming that the current requests are all that are needed for processes to complete Check if the current requests can be satisfied by the available resources If a deadlock is detected recover from it

Deadlock Detection Algorithm Mark each process that has zero row vector in A Initialize a temporary vector W to V Find an unmarked process i such that the i th row of Q is less than or equal to W Q is a request matrix: Q ij is the amount of resources of type j requested by process i Terminate the algorithm if no such process is found If such a row is found Mark process i Add i th row of A to W and go to the 3 rd step Any unmarked processes are deadlocked processes

Deadlock Detection Example Mark P4 because P4 has no allocated resources Set W = (0 0 0 0 1) = V Because the 3 rd row of Q is less than or equal to W Mark P3 and update W as W = W + (0 0 0 1 0) = (0 0 0 1 1) Terminate because no other unmarked process has a row in Q that is less than or equal to W P1 and P2 are unmarked and they are deadlocked

Recovery Abort all deadlocked processes One of the most common approaches Rollback all deadlocked processes to some previously defined checkpoint and restart Successively abort deadlocked processes until deadlock is removed Successively rollback processes to a checkpoint and restart until deadlock is removed