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

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

Chapter 8: Deadlocks. The Deadlock Problem

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

Chapter 7: Deadlocks

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

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

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

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.

System Model. Types of resources Reusable Resources Consumable Resources

The Deadlock Problem

Chapter 7: Deadlocks

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

Bridge Crossing Example

Deadlocks. Deadlock Overview

Chapter 8: Deadlocks. The Deadlock Problem

Chapter 7: Deadlocks

Contents. Chapter 8 Deadlocks

Chapter 7: Deadlocks

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

Deadlocks. Prepared By: Kaushik Vaghani

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

CSE Opera+ng System Principles

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

Deadlocks. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

CS307 Operating Systems Deadlocks

Module 7: Deadlocks. The Deadlock Problem

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

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

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

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

CMSC 412. Announcements

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

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

Chapter 8: Deadlocks. Operating System Concepts with Java

Deadlocks. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

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

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

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

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

OPERATING SYSTEMS. Deadlocks

The Deadlock Problem (1)

CS420: Operating Systems. Deadlocks & Deadlock Prevention

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

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

Deadlocks. System Model

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.

Principles of Operating Systems

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

The Deadlock Problem

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

Deadlocks. Dr. Yingwu Zhu

Operating Systems 2015 Spring by Euiseong Seo DEAD LOCK

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

Principles of Operating Systems

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

CSC 539: Operating Systems Structure and Design. Spring 2005

The Deadlock Problem

Deadlock. Chapter Objectives

CS307: Operating Systems

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

Lecture 7 Deadlocks (chapter 7)

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

UNIT-3 DEADLOCKS DEADLOCKS

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

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

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

Deadlock Risk Management

ECE519 Advanced Operating Systems

Module 6: Deadlocks. Reading: Chapter 7

Introduction to Deadlocks

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

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

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

Part II Process M anagement Management Chapter 7: Deadlocks Fall 2010

University of Babylon / College of Information Technology / Network Department. Operating System / Dr. Mahdi S. Almhanna & Dr. Rafah M.

CHAPTER 7 - DEADLOCKS

Chapter 7: Deadlocks

Chapter - 4. Deadlocks Important Questions

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

Process-1 requests the tape unit, waits. In this chapter, we shall analyze deadlocks with the following assumptions:

Deadlock and Starvation

Outlook. Deadlock Characterization Deadlock Prevention Deadlock Avoidance

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

Operating Systems ECE344. Ding Yuan

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

Deadlock. Pritee Parwekar

CSE 306/506 Operating Systems Deadlock. YoungMin Kwon

Deadlocks. The Deadlock Problem. Bridge Crossing Example. Topics

Chapter 7: Deadlocks CS370 Operating Systems

Deadlock. Operating Systems. Autumn CS4023

Chapter 8: Deadlocks. The Deadlock Problem

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

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

Roadmap. Safe State. Deadlock Avoidance. Basic Facts. Safe, Unsafe, Deadlock State. Tevfik Koşar. CSC Operating Systems Spring 2007

Chapter 6 Concurrency: Deadlock and Starvation

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

Chapter 3. Deadlocks

The deadlock problem

Transcription:

Deadlocks Mehdi Kargahi School of ECE University of Tehran Spring 2008

What is a Deadlock Processes use resources in the following sequence: Request Use Release A number of processes may participate in a deadlock Example Three processes on three CD/RW drives: cyclic wait Two processes requesting printer and DVD drive

Necessary Condition for Deadlock Mutual exclusion Hold and wait No preemption Circular wait

Resource-Allocation Graph P = {P 1,, P n } R = {R 1,, R m } Request edge: P i R j Assignment edge: R j P i

Resource-Allocation Graph with a Deadlock

Resource-Allocation Graph with a Cycle but no Deadlock Deadlock Cycle Cycle Deadlock is probable

Deadlock Handling Deadlock prevention or deadlock avoidance Prevention: To ensure deadlock will never occur Avoidance: Knowing the resource requirements, deadlock will by avoided on each allocation Deadlock detection and recovery Ignoring deadlock (assuming it never occurs)

Deadlock Prevention At least one of the necessary conditions for deadlock should not be held 1. Mutual exclusion This condition cannot be denied, unless for sharable resources, e.g., a real-only file

Deadlock Prevention 2. Hold and wait Method1: Each process request and be allocated all its resources before execution (no waiting) Method2: A process requests resources only when it has none (no holding) Disadvantages of Method1: low resource utilization Method2: starvation

Deadlock Prevention 3. No preemption A protocol A waiting process will implicitly release its current resources If a process requests some resources Resources are free allocate them Resources are held by a waiting process preempt the resources and allocate them to this process Otherwise, the requesting process must wait This protocol can be applied only to resources such as CPU registers or memory space whose states can be easily saved and restored later Disadvantages: low resource utilization and starvation

Deadlock Prevention 4. Cyclic wait One way to ensure that this condition may not hold Imposing a total ordering of all resource types R={R 1,, R m }, F: R N Requiring that each process requests resources in an increasing order of enumeration, or Releasing the high-order resource before requesting a low-order resource Proof? This protocol is implemented in Mainframes

Deadlock Avoidance Deadlock is potentially possible, but on every resource request, the safety of the allocation is examined More information is required Available resources as well as the allocated ones Maximum demands of the resources by each process A state is safe if the system can allocate resources to each process (up to its maximum) in some order and still avoid a deadlock A system is in a safe state only if there exists a safe sequence

Deadlock Avoidance Example: A system consists of 12 magnetic tapes and three processes Is the requests safe? Safe sequence: <p 1, p 0, p 2 > What if P 2 request a tape?

Resource-Allocation-Graph Algorithm Only applicable to one-instance resources Claim edge An unsafe state

Banker s Algorithm Applicable to multiple-instance resources n processes m resources Available 1 m : Available [j] = k Max n m : Max [i][j] = k Allocation n m : Allocation [i][j] = k Need n m : Need [i][j] = k Need [i][j] = Max [i][j] - Allocation [i][j] These data structures vary over time in both size and value Allocation i, Need i, and Max i show the row related to P i X Y iff X[i] Y[i] for all i=1, 2, X<Y iff X Y and X Y

Banker s Algorithm Safety Algorithm

Banker s Algorithm Resource-Request Algorithm

Example The state is safe What if Request 1 =(1, 0, 2)? Request 4 =(3, 3, 0)? Request 0 =(0, 2, 0)?

Deadlock Detection Single instance of each resource type Resource allocation graph Wait-for graph Deadlock detection requires O(n 2 ) operations

Deadlock Detection Several instances of a resource type Deadlock detection requires m n 2 operations

Example This state is safe Safe sequence: P 2 makes one additional request of C Which processes are in deadlock?

How often the detection algorithm should be invoked? On each allocation High overhead The process creating the deadline can be detected Low frequency of the detection algorithm Low overhead More than one cycles may be detected Higher frequency but when the system isn t overloaded!! Even if the system is overloaded, large number of cycles due to less frequent detection results in performance loss

Deadlock Recovery Process termination Abort all deadlocked processes Abort one process at a time until the deadlock cycle is eliminated Cost factors to select the next victim

Deadlock Recovery Resource preemption Selecting a victim Which resources and which processes are to be preempted? (Minimizing the cost) Rollback Total rollback vs. checkpointing Starvation If the same process is always selected as the victim!! Cost factor: number of roll-backs