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

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

CS370 Operating Systems

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

CS370 Operating Systems

Operating Systems 2015 Spring by Euiseong Seo DEAD LOCK

Chapter 7: Deadlocks CS370 Operating Systems

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

CHAPTER 7 - DEADLOCKS

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

CS370 OperaBng Systems

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

Operating Systems. Deadlock. Lecture 7 Michael O Boyle

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

Potential Deadlock Example

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. Operating System Concepts 9th Edition DM510-14

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

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

Chapter 8: Deadlocks. Operating System Concepts with Java

The Deadlock Problem

Chapter 7: Deadlocks

CS370 Operating Systems

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

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

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

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

System Model. Types of resources Reusable Resources Consumable Resources

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

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

Lecture 7 Deadlocks (chapter 7)

Chapter 7: Deadlocks

Principles of Operating Systems

Deadlocks. Deadlock Overview

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

CS307: Operating Systems

Principles of 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

What is the Race Condition? And what is its solution? What is a critical section? And what is the critical section 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 Deadlock Problem (1)

The Deadlock Problem

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

Deadlock Risk Management

The Deadlock Problem

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

Deadlocks. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

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 and Starvation

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

UNIT-3 DEADLOCKS DEADLOCKS

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

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

Last Class: Monitors. Real-world Examples

More on Synchronization and Deadlock

OPERATING SYSTEMS. Deadlocks

Deadlocks. Dr. Yingwu Zhu

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

Chapter 8: Deadlocks. The Deadlock Problem

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

Deadlock Risk Management

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

Roadmap. Tevfik Koşar. CSE 421/521 - Operating Systems Fall Lecture - X Deadlocks - I. University at Buffalo. Synchronization structures

Roadmap. Problems with Semaphores. Semaphores. Monitors. Monitor - Example. Tevfik Koşar. CSE 421/521 - Operating Systems Fall 2012

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

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. See example box in text page 318 for mutex deadlock 7.6 Silberschatz, Galvin and Gagne 2013

Deadlock with Mutex Locks 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 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 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 Require process to request and be allocated all its resources before it begins execution, or 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. Low resource utilization; starvation possible 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. 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. How to fix this situation? 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

To-do-list before next class 1) Download Android x-86 ISO from website. http://www.android-x86.org/download Version: android-x86-4.4-r2.iso 2)Install Android 4.4 using Virtual Box http://www.howtogeek.com/164570/how-to-install-android-in-virtualbox 3) The following is a link for installing Eclipse Android Development plug in. http://developer.android.com/sdk/installing/installing-adt.html#configure 7.26 Silberschatz, Galvin and Gagne 2013