Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

Similar documents
Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

CS370 Operating Systems

Deadlock Prevention. Deadlock can be prevented if 1 of the 4 conditions cannot hold

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

CS370 Operating Systems

Chapter 7: Deadlocks CS370 Operating Systems

Operating Systems 2015 Spring by Euiseong Seo DEAD LOCK

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

Chapter 7: Deadlocks. Chapter 7: Deadlocks. Deadlock Example. Chapter Objectives

CS370 Operating Systems

CS370 Operating Systems

CS370 OperaBng Systems

CHAPTER 7 - DEADLOCKS

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

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

Operating Systems. Deadlock. Lecture 7 Michael O Boyle

Potential Deadlock Example

CHAPTER 7: DEADLOCKS. By I-Chen Lin Textbook: Operating System Concepts 9th Ed.

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

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

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

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

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

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

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 7: Deadlocks. Operating System Concepts with Java 8 th Edition

Silberschatz, Galvin and Gagne 2013! CPU cycles, memory space, I/O devices! " Silberschatz, Galvin and Gagne 2013!

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

Chapter 8: Deadlocks. The Deadlock Problem

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

Deadlock. Operating Systems. Autumn CS4023

Chapter 7: Deadlocks

CSE Opera+ng System Principles

Chapter 8: Deadlocks. The Deadlock Problem

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

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

Chapter 7: Deadlocks. Chapter 7: Deadlocks. System Model. Chapter Objectives

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

Module 7: Deadlocks. The Deadlock Problem

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

Chapter 7: Deadlocks

CS370 Operating Systems

Chapter 8: Deadlocks. Operating System Concepts with Java

The Deadlock Problem

Chapter 7: Deadlocks

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

Chapter 8: Deadlocks

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

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

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

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

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

Lecture 7 Deadlocks (chapter 7)

System Model. Types of resources Reusable Resources Consumable Resources

Principles of Operating Systems

CS420: Operating Systems. Deadlocks & Deadlock Prevention

CS307 Operating Systems Deadlocks

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

Chapter 7: Deadlocks

Deadlocks. Deadlock Overview

Principles of Operating Systems

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

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

CS307: Operating Systems

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

Deadlocks. Prepared By: Kaushik Vaghani

CMSC 412. Announcements

The Deadlock Problem (1)

The Deadlock Problem

Module 6: Deadlocks. Reading: Chapter 7

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

Bridge Crossing Example

Roadmap. Tevfik Koşar. CSE 421/521 - Operating Systems Fall Lecture - XI Deadlocks - II. University at Buffalo. Deadlocks. October 6 th, 2011

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.

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

The Deadlock Problem

Deadlock Risk Management

Deadlocks. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

More on Synchronization and Deadlock

Process Synchronisation (contd.) Deadlock. Operating Systems. Spring CS5212

Deadlock and Starvation

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

UNIT-3 DEADLOCKS DEADLOCKS

Deadlocks. Dr. Yingwu Zhu

Roadmap. Tevfik Ko!ar. CSC Operating Systems Spring Lecture - X Deadlocks - II. Louisiana State University. Deadlocks

Deadlock. Deadlock. Deadlock. Deadlock 10/7/2014. CS341: Operating System. Deadlock Conditions Mutex, Hold & Wait, No Preemption and Circular wait

Last Class: Monitors. Real-world Examples

OPERATING SYSTEMS. Deadlocks

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

Deadlocks. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Deadlock. Chapter Objectives

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

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

Frequently asked questions from the previous class survey

CS370: Operating Systems [Spring 2017] Dept. Of Computer Science, Colorado State University

Chapter 8: Deadlocks. The Deadlock Problem

CSC Operating Systems Spring Lecture - XII Midterm Review. Tevfik Ko!ar. Louisiana State University. March 4 th, 2008.

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

Deadlock Risk Management

Transcription:

Chapter 7: Deadlocks Silberschatz, Galvin and Gagne 2013

Chapter 7: Deadlocks System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance Deadlock Detection Recovery from Deadlock 7.2 Silberschatz, Galvin and Gagne 2013

Chapter Objectives To develop a description of deadlocks, which prevent sets of concurrent processes from completing their tasks To present a number of different methods for preventing or avoiding deadlocks in a computer system 7.3 Silberschatz, Galvin and Gagne 2013

An Example 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. A law passed by the Kansas legislature early in the 20 th century. 7.4 Silberschatz, Galvin and Gagne 2013

System Model System consists of resources Resource types R 1, R 2,..., R m CPU cycles, memory space, I/O devices Each resource type R i has W i instances. Synchronization tools, such as mutex locks and semaphores are also considered system resources. Each process utilizes a resource as follows: request use release 7.5 Silberschatz, Galvin and Gagne 2013

Deadlock with Mutex Locks Deadlocks can occur via system calls, locking, etc. The locking tools (e.g., mutex locks, semaphores) are designed to avoid race conditions. However, inappropriate usage of them can lead to deadlocks. 7.6 Silberschatz, Galvin and Gagne 2013

Example Deadlock two or more processes are waiting indefinitely for an event that can be caused by only one of the waiting processes Let S and Q be two semaphores initialized to 1 P 0 P 1 wait(s); wait(q); wait(q); wait(s);...... signal(s); signal(q); signal(q); signal(s); 7.7 Silberschatz, Galvin and Gagne 2013

Deadlock Characterization Deadlock can arise if four conditions hold simultaneously. Mutual exclusion: only one process at a time can use a resource Hold and wait: a process holding at least one resource is waiting to acquire additional resources held by other processes No preemption: a resource can be released only voluntarily by the process holding it, after that process has completed its task Circular wait: there exists a set {P 0, P 1,, P n } of waiting processes such that P 0 is waiting for a resource that is held by P 1, P 1 is waiting for a resource that is held by P 2,, P n 1 is waiting for a resource that is held by P n, and P n is waiting for a resource that is held by P 0. 7.8 Silberschatz, Galvin and Gagne 2013

Resource-Allocation Graph A set of vertices V and a set of edges E. V is partitioned into two types: P = {P 1, P 2,, P n }, the set consisting of all the processes in the system R = {R 1, R 2,, R m }, the set consisting of all resource types in the system request edge directed edge P i R j assignment edge directed edge R j P i 7.9 Silberschatz, Galvin and Gagne 2013

Resource-Allocation Graph (Cont.) Process Resource Type with 4 instances P i requests instance of R j P i P i is holding an instance of R j R j P i R j 7.10 Silberschatz, Galvin and Gagne 2013

Example of a Resource Allocation Graph Do we have a deadlock here? It can be shown that if the graph contains no cycles, then no process in the system is deadlocked. If the graph does contain a cycle, then a deadlock may exist. 7.11 Silberschatz, Galvin and Gagne 2013

Resource Allocation Graph With A Deadlock 7.12 Silberschatz, Galvin and Gagne 2013

Graph With A Cycle But No Deadlock 7.13 Silberschatz, Galvin and Gagne 2013

Basic Facts If graph contains no cycles no deadlock If graph contains a cycle if only one instance per resource type, then deadlock if several instances per resource type, possibility of deadlock Draw a resource-allocation graph to illustrate the deadlock problem on slide 7. Draw a resource-allocation graph for the dinning philosophers problem. 7.14 Silberschatz, Galvin and Gagne 2013

Methods for Handling Deadlocks Ensure that the system will never enter a deadlock state: Deadlock prevention Deadlock avoidence Allow the system to enter a deadlock state and then recover Ignore the problem and pretend that deadlocks never occur in the system; used by most operating systems, including UNIX 7.15 Silberschatz, Galvin and Gagne 2013

Deadlock Prevention Restrain the ways request can be made Mutual Exclusion not required for sharable resources (e.g., read-only files); must hold for non-sharable resources Hold and Wait must guarantee that whenever a process requests a resource, it does not hold any other resources Method 1: Require process to request and be allocated all its resources before it begins execution, Method 2: allow process to request resources only when the process has none allocated to it. Consider a process that copies data from a DVD driver to a file on disk, sorts the file, and then prints the results to a printer. Method 1: request all three resources in the beginning. Method 2: request DVD and file first; release both DVD and file; and then request file and printer. Low resource utilization; starvation possible (a process that needs several popular resources may have to wait indefinitely). 7.16 Silberschatz, Galvin and Gagne 2013

Deadlock Prevention (Cont.) No Preemption If a process that is holding some resources requests another resource that cannot be immediately allocated to it, then all resources currently being held are released Preempted resources are added to the list of resources for which the process is waiting Process will be restarted only when it can regain its old resources, as well as the new ones that it is requesting 7.17 Silberschatz, Galvin and Gagne 2013

Deadlock Prevention (Cont.) Circular Wait impose a total ordering of all resource types, and require that each process requests resources in an increasing order of enumeration A process can initially request any number of instances of a resource type. After that, the process can request instances of resource type if and only if the order of the new resource is greater than the existing resource. Alternatively, we can require that a process requesting an instance of resource type must have released any resources that have smaller order numbers. Using this idea to solve the dinning philosopher problem 7.18 Silberschatz, Galvin and Gagne 2013

Deadlock Example /* thread one runs in this function */ void *do_work_one(void *param) { } pthread_mutex_lock(&first_mutex); pthread_mutex_lock(&second_mutex); /** * Do some work */ pthread_mutex_unlock(&second_mutex); pthread_mutex_unlock(&first_mutex); pthread_exit(0); /* thread two runs in this function */ void *do_work_two(void *param) { } pthread_mutex_lock(&second_mutex); pthread_mutex_lock(&first_mutex); /** * Do some work */ pthread_mutex_unlock(&first_mutex); pthread_mutex_unlock(&second_mutex); pthread_exit(0); 7.19 Silberschatz, Galvin and Gagne 2013

Deadlock Example with Lock Ordering void transaction(account from, Account to, double amount) { } mutex lock1, lock2; lock1 = get_lock(from); lock2 = get_lock(to); acquire(lock1); acquire(lock2); withdraw(from, amount); deposit(to, amount); release(lock2); release(lock1); Transactions 1 and 2 execute concurrently. Transaction 1 transfers $25 from account A to account B, and Transaction 2 transfers $50 from account B to account A Reason: the locks are acquired dynamically. 7.20 Silberschatz, Galvin and Gagne 2013

Deadlock Avoidance Requires that the system has some additional a priori information available Simplest and most useful model requires that each process declare the maximum number of resources of each type that it may need The deadlock-avoidance algorithm dynamically examines the resource-allocation state to ensure that there can never be a circular-wait condition Resource-allocation state is defined by the number of available and allocated resources, and the maximum demands of the processes 7.21 Silberschatz, Galvin and Gagne 2013

Deadlock Detection Allow system to enter deadlock state Detection algorithm Recovery scheme 7.22 Silberschatz, Galvin and Gagne 2013

Recovery from Deadlock: Process Termination Abort all deadlocked processes Abort one process at a time until the deadlock cycle is eliminated In which order should we choose to abort? 1. Priority of the process 2. How long process has computed, and how much longer to completion 3. Resources the process has used 4. Resources process needs to complete 5. How many processes will need to be terminated 6. Is process interactive or batch? 7.23 Silberschatz, Galvin and Gagne 2013

Recovery from Deadlock: Resource Preemption Selecting a victim minimize cost Rollback return to some safe state, restart process for that state Starvation same process may always be picked as victim, include number of rollback in cost factor 7.24 Silberschatz, Galvin and Gagne 2013

End of Chapter 7 Silberschatz, Galvin and Gagne 2013