Comp 204: Computer Systems and Their Implementation. Lecture 9: Deadlock

Similar documents
Concurrent Programming. Concurrent Programming. Today. Comp 104: Operating Systems Concepts 05/01/2017. Concurrent Programming & Threads

UNIT-3 DEADLOCKS DEADLOCKS

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

CSE Opera+ng System Principles

Module 6: Deadlocks. Reading: Chapter 7

Chapter 3. Deadlocks

Last Class: Monitors. Real-world Examples

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

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

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

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

Chapter 3. Deadlocks

CSC 539: Operating Systems Structure and Design. Spring 2005

Deadlock and Starvation

Deadlocks. Dr. Yingwu Zhu

Chapter 8: Deadlocks. The Deadlock Problem

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

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

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

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

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

Deadlock. Chapter Objectives

Chapter 7: Deadlocks

The Deadlock Problem (1)

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

Deadlocks. Prepared By: Kaushik Vaghani

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

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

Deadlocks. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

OPERATING SYSTEMS. Deadlocks

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

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

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

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

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.

The Deadlock Problem

Chapter 8: Deadlocks

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

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

CS307: Operating Systems

Chapter 6. Deadlocks

Introduction to Deadlocks

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

Principles of Operating Systems

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

The Deadlock Problem

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

Chapter 7: Deadlocks

COS 318: Operating Systems. Deadlocks. Jaswinder Pal Singh Computer Science Department Princeton University

Deadlocks. System Model

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

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

Principles of Operating Systems

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

CS420: Operating Systems. Deadlocks & Deadlock Prevention

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

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

Chapter 8: Deadlocks. The Deadlock Problem

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.

Frequently asked questions from the previous class survey

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

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

Resources. Chapter 3. Deadlocks. Resources. Resources

Chapter 7: Deadlocks CS370 Operating Systems

Lecture 7 Deadlocks (chapter 7)

CS450/550 Operating Systems

System Model. Types of resources Reusable Resources Consumable Resources

Fig Bridge crossing - deadlock

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

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

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

CMSC 412. Announcements

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

UNIT 4 DEADLOCKS 4.0 INTRODUCTION

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

Chapter 3: Deadlocks

Operating Systems. Deadlocks. Stephan Sigg. November 30, Distributed and Ubiquitous Systems Technische Universität Braunschweig

Concurrency: Deadlock and Starvation. Chapter 6

Module 7: Deadlocks. The Deadlock Problem

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

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

Chapter 7: Deadlocks

Chapter 8: Deadlocks. Operating System Concepts with Java

More on Synchronization and Deadlock

Deadlock. Operating Systems. Autumn CS4023

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

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

CSE 380 Computer Operating Systems

Chapter 7: Deadlocks

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

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

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

Deadlocks. Deadlock Overview

COMP 3713 Operating Systems Slides Part 3. Jim Diamond CAR 409 Jodrey School of Computer Science Acadia University

CS307 Operating Systems Deadlocks

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

Chapter 6. Deadlock. (A Quick Introduction)

Bridge Crossing Example

Transcription:

Comp 204: Computer Systems and Their Implementation Lecture 9: Deadlock 1

Today Deadlock Definition Resource allocation graphs Detecting and dealing with deadlock 2

Deadlock When two trains approach each other at a crossing, both shall come to a full stop and neither shall start up again until the other has gone. -- Kansas law A set of processes is deadlocked (in deadly embrace) if each process in the set is waiting for an event only another process in the set can cause. These events usually relate to resource allocation 3

Resource Allocation OS must allocate and share resources sensibly Resources may be CPUs Peripheral devices (printers etc.) Memory Files Data Programming objects such as semaphores, object locks etc. Usual process/thread sequence is request-use-release Often via system calls 4

Creating Deadlock In its simplest form, deadlock will occur in the following situation: process A is granted resource X and then requests resource Y process B is granted resource Y and then requests resource X both resources are non-shareable (e.g. tape drive, printer) both resources are non-preemptible (i.e. cannot be taken away from their owner processes) 5

Question Consider the following situation regarding two processes (A and B), and two resources (X and Y): Process A is granted resource X and then requests resource Y. Process B is granted resource Y and then requests resource X. Which of the following is (are) true about the potential for deadlock? I. Deadlock can be avoided by sharing resource Y between the two processes II. Deadlock can be avoided by taking resource X away from process A III. Deadlock can be avoided by process B voluntarily giving up its control of resource Y a) I only b) I and II only c) I and III only d) II and III only e) I, II and III Answer: e I, II and III as all three options will avoid exclusive ownership of the resources. 6

Resource Allocation Graphs Consist of a set of vertices V and a set of edges E V is partitioned into two types: Set of processes, P = {P 1, P 2,, P n } Set of resource types, R = {R 1, R 2,, R m } e.g. printers Include instances of each type 7

Resource Allocation Graphs E is a set of directed edges Request edge from process to resource type, denoted P i R j States that process P i has requested an instance of resource type R j and is currently waiting for it Assignment edge from resource instance to process, denoted R j P i States that an instance of a resource type R j has been allocated to process P i Request edges are transformed to assignment edges when request satisfied 8

Example Graph R1 R3 P1 P2 P3 R2 R4 No cycles, so no deadlock. 9

Example Graph The previous diagram depicts the following: Processes, resource types, edges P = {P 1, P 2, P 3 } R = {R 1, R 2, R 3, R 4 } E = {P 1 R 1, P 2 R 3, R 1 P 2, R 2 P 2, R 2 P 1, R 3 P 3 } Resource instances: One instance of resource type R 1 Two instances of resource type R 2 One instance of resource type R 3 Three instances of resource type R 4 10

Process states: Example Graph Process P 1 is holding an instance of resource type R 2 and is waiting for an instance of resource type R 1 Process P 2 is holding an instance of resource type R 1 and R 2 and is waiting for an instance of resource type R 3 Process P 3 is holding an instance of resource type R 3 11

Resource Allocation Graphs In resource allocation graphs we can show that deadlock has not occurred if there are no cycles in the graph If cycles do exist in the graph, this indicates that deadlock may be present If each resource type consists of exactly one instance, a cycle indicates that deadlock has occurred If each resource type consists of several instances, a cycle does not necessarily indicate that deadlock has occurred Example: On previous graph, suppose P 3 now requests R 2 12

Example Graph (2) R1 R3 P1 P2 P3 R2 R4 In general, a cycle indicates there may be deadlock. 13

Cycles Suppose P 3 now requests R 2 a request edge P 3 R 2 is added to the previous graph to show this There are now two cycles in the system: P 1 R 1 P 2 R 3 P 3 R 2 P 1 P 2 R 3 P 3 R 2 P 2 From this we can see that P 1, P 2, and P 3 are deadlocked Now consider the following the resource allocation graph 14

Another Example R1 P2 P1 P3 R2 P4 Deadlock? 15

Dealing with Deadlock Prevention Devise a system in which deadlock cannot possibly occur Avoidance Make decisions dynamically as to which resource requests can be granted Detection and recovery Allow deadlock to occur, then cure it Ignore the problem Common approach (e.g. UNIX, JVM) 16

Exercise Why might ignoring the problem of deadlock be a useful approach? 17

Deadlock Prevention Techniques Force processes to claim all resources in one operation Problem of under-utilisation Require processes to claim resources in pre-defined order e.g. tape drive before printer always Grant request only if all allocated resources released first e.g. transferring file from tape to disk, then disk to printer 18

Deadlock Avoidance Requires information about which resources a process plans to use When a request made, system analyses allocation graph to see if it may lead to deadlock If so, process forced to wait Problems of reduced throughput and process starvation 19

Deadlock Avoidance: Safe State When a process requests an available resource, system must decide if immediate allocation leaves it in a safe state System is in such a state if for the sequence of processes <P 1, P 2,, P n >, for each P i, the resources that P i can still request can be satisfied by currently available resources plus the resources held by all the P j, with j < i. Thus: If P i resource requirements are not immediately available, then P i can wait until all P j have finished When P j is finished, P i can obtain its required resources, execute, return allocated resources, and terminate When P i terminates, P i +1 can obtain its required resources, and so on 20

Deadlock Avoidance: Safe State If the system is in a safe state there are no deadlocks If the system is in an unsafe state, there is the possibility of deadlock an unsafe state may lead to it Deadlock avoidance: ensure that the system will never enter an unsafe state Avoidance algorithms make use of this concept of a safe state by ensuring that the system always remains in it 21

Detection and Recovery Systems that do not have deadlock prevention or avoidance mechanisms and do not want to ignore the problem must provide the following to deal with deadlock: An algorithm to analyse the state of the system to see if deadlock has occurred A recovery scheme Method depends upon whether or not there are multiple instances of each resource type 22

Detection and Recovery If there are multiple instances of a resource type detection algorithms can be used that track: the number of available resources of each type the number of resources of each type allocated to each process the current requests of each process If all resources have only a single instance, can make use of a wait-for graph Variant of a resource-allocation graph Obtained from resource allocation graph by removing nodes of type resource and collapsing the appropriate edges 23