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

Similar documents
Resources. Chapter 3. Deadlocks. Resources. Resources

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

Chapter 6. Deadlocks

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

Chapter 3. Deadlocks

Chapter 3. 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.

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

CS450/550 Operating Systems

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

Chapter 3: Deadlocks

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

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

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

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

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

Chapter 3: Deadlocks. Chapter 3

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

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

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

Concurrency problems. To do. q Non-deadlock bugs q Resources & deadlocks q Dealing with deadlocks q Other issues q Next Time: I/O and file systems

Deadlocks. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

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

COMPUTER SCIENCE 4500 OPERATING SYSTEMS

Concurrency problems. q Non-deadlock bugs q Resources & deadlocks q Dealing with deadlocks q Other issues q Next Time: I/O and file systems

Deadlocks. Operating Systems. Resources. Deadlocks

Computer Science 4500 Operating Systems. In This Module. Deadlock Definition. Module 7 Deadlocks

Computer Science 4500 Operating Systems

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

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

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

11 Resource Management Deadlock and Starvation

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

Operating Systems. Deadlocks

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

UNIT 4 DEADLOCKS 4.0 INTRODUCTION

6. Concurrency: Deadlock

Chapter 6 - Deadlocks

Deadlocks. Dr. Yingwu Zhu

CSE 380 Computer Operating Systems

Chapter 6. Deadlock. (A Quick Introduction)

OPERATING SYSTEMS. Deadlocks

Deadlock 1 Chapter 6

Deadlock and Starvation

CS Operating Systems

CS Operating Systems

CSE 306/506 Operating Systems Deadlock. YoungMin Kwon

Chap. 3. Input/Output

Concurrency: Deadlock and Starvation. Chapter 6

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

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

Principles of Operating Systems

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.

Deadlock Risk Management

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

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

Administrivia. Assignments 0 & 1 Class contact for the next two weeks Next week. Following week

More on Synchronization and Deadlock

Deadlock 1 Chapter 6

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

Operating Systems ECE344. Ding Yuan

Chapter 7: Deadlocks

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

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.

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

CMPT 300 Introduction to Operating Systems

Deadlocks. Copyright : University of Illinois CS 241 Staff 1

We need a formal algorithm, as visual inspection is not sufficient Many algorithms for detecting cycles in a directed graph are known o Below is a

System Model. Deadlocks. Deadlocks. For example: Semaphores. Four Conditions for Deadlock. Resource Allocation Graph

VI. Deadlocks. What is a Deadlock? Intended Schedule. Deadlock Problem (1) ???

VI. Deadlocks Operating Systems Prof. Dr. Marc H. Scholl DBIS U KN Summer Term

Deadlocks. System Model

Deadlock and Starvation

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

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

The Deadlock Problem

Chapter 7: Deadlocks

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

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

Chapter 7: Deadlocks

Process Management. Deadlock. Process Synchronization. Management Management. Starvation

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

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

Chapter 8: Deadlocks

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

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

Deadlocks. Prepared By: Kaushik Vaghani

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

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

Chapter 7: Deadlocks 1

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

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

Chapter 8: Deadlocks. The Deadlock Problem

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

Module 6: Deadlocks. Reading: Chapter 7

Deadlocks. Copyright : University of Illinois CS 241 Staff 1

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

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

Contents. Chapter 8 Deadlocks

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

Transcription:

hapter Deadlocks.. esource.. Introduction to deadlocks.. The ostrich algorithm.4. Deadlock detection and recovery.5. Deadlock avoidance.6. Deadlock prevention.7. Other issues Learning Outcomes Understand what deadlock is and how it can occur when giving mutually exclusive access to multiple resources. Understand several approaches to mitigating the issue of deadlock in operating systems. Including deadlock detection and recovery, deadlock avoidance, and deadlock prevention. esources esources Examples of computer resources printers tape drives Tables in a database Processes need access to resources in reasonable order Suppose a process holds resource A and requests resource B at same time another process holds B and requests A both are blocked and remain so Deadlocks occur when processes are granted exclusive access to devices we refer to these devices generally as resources Preemptable resources can be taken away from a process with no ill effects Nonpreemptable resources will cause the process to fail if taken away 4 esources Sequence of events required to use a resource. request the resource. use the resource. release the resource Must wait if request is denied requesting process may be blocked may fail with error code 5 Example esource usage semaphore res_, res_; void proc_a() { down(&res_); down(&res_); use_both_res(); up(&res_); up(&res_); } void proc_b() { down(&res_); down(&res_); use_both_res(); up(&res_); up(&res_); } semaphore res_, res_; void proc_a() { down(&res_); down(&res_); use_both_res(); up(&res_); up(&res_); } void proc_b() { down(&res_); down(&res_); use_both_res(); up(&res_); up(&res_); } 6

Introduction to Deadlocks Formal definition : A set of processes is deadlocked if each process in the set is waiting for an event that only another process in the set can cause Usually the event is release of a currently held resource None of the processes can run release resources be awakened 7 Four onditions for Deadlock. Mutual exclusion condition each resource assigned to process or is available. Hold and wait condition process holding resources can request additional. No preemption condition previously granted resources cannot forcibly taken away 4. ircular wait condition must be a circular chain of or more processes each is waiting for resource held by next member of the chain 8 Deadlock Modeling Modeled with directed graphs resource assigned to process A process B is requesting/waiting for resource S process and D are in deadlock over resources T and U 9 Deadlock Strategies for dealing with Deadlocks. just ignore the problem altogether. detection and recovery. dynamic avoidance careful resource allocation 4. prevention negating one of the four necessary conditions Deadlock Modeling A B Deadlock Modeling How deadlock occurs (o) (p) (q) How deadlock can be avoided

Approach : The Ostrich Algorithm Pretend there is no problem easonable if deadlocks occur very rarely cost of prevention is high Example of cost, only one process runs at a time UNIX and Windows takes this approach for some of the more complex resources to manage It s a trade off between onvenience (engineering approach) orrectness (mathematical approach) Approach : Detection and ecovery Need a method to determine if a system is deadlocked. Assuming deadlocked is detected, we need a method of recovery to restore progress to the system. 4 Approach Detection with One esource of Each Type What about resources with multiple units? We need an approach for dealing with resources that consist of more than a single unit. Note the resource ownership and requests A cycle can be found within the graph, denoting deadlock 5 6 Detection with Multiple esources of Each Type Note the following invariant Sum of current resource allocation + resources available resources that exist Data structures needed by deadlock detection algorithm 7 n i + A ij j E j 8

4 9 Detection with Multiple esources of Each Type An example for the deadlock detection algorithm Detection Algorithm. Look for an unmarked process Pi, for which the i-th row of is less than or equal to A. If found, add the i-th row of to A, and mark Pi. Go to step. If no such process exists, terminate. emaining processes are deadlocked ) (4 A( ) (4 A( ) (4 A( 4 ) (4 A(

5 5 ) (4 A(4 6 ) (4 A(4 7 ) (4 A(4 8 ) (4 A(4 9 Algorithm terminates with no unmarked processes We have no dead lock Example : Deadlock Detection Suppose, P needs a D-OM as well as Tapes and a Plotter ) (4 A(

ecovery from Deadlock ecovery from Deadlock ecovery through preemption take a resource from some other process depends on nature of the resource ecovery through rollback checkpoint a process periodically use this saved state restart the process if it is found deadlocked ecovery through killing processes crudest but simplest way to break a deadlock kill one of the processes in the deadlock cycle the other processes get its resources choose process that can be rerun from the beginning Approach Deadlock Avoidance Deadlock Avoidance esource Trajectories Instead of detecting deadlock, can we simply avoid it? YES, but only if enough information is available in advance. Maximum number of each resource required Two process resource trajectories 4 Safe and Unsafe States A state is safe if The system is not deadlocked There exists a scheduling order that results in every process running to completion, even if they all request their maximum resources immediately Safe and Unsafe States Note: We have units of the resource (a) (b) (c) (d) (e) Demonstration that the state in (a) is safe 5 6 6

Safe and Unsafe States A requests one extra unit resulting in (b) (a) (b) (c) (d) Demonstration that the state in b is not safe Safe and Unsafe State Unsafe states are not necessarily deadlocked With a lucky sequence, all process may complete However, we cannot guarantee that they will complete (not deadlock) Safe states guarantee we will eventually complete all processes Deadlock avoidance algorithm Only grant requests that result in safe states 7 8 Bankers Algorithm Modelled on a Banker with ustomers The banker has a limited amount of money to loan customers Limited number of resources Each customer can borrow money up to the customer s credit limit Maximum number of resources required Basic Idea Keep the bank in a safe state So all customers are happy even if they all request to borrow up to their credit limit at the same time. ustomers wishing to borrow such that the bank would enter an unsafe state must wait until somebody else repays their loan such that the the transaction becomes safe. 9 The Banker's Algorithm for a Single esource (a) (b) (c) Three resource allocation states safe safe unsafe 4 Banker's Algorithm for Multiple esources Bankers Algorithm is used rarely in practice It is difficult (sometime impossible) to know in advance the resources a process will require the number of processes in a dynamic system Example of banker's algorithm with multiple resources Should we allow a request by B & E for scanner to succeed?? 4 4 7

Approach 4: Deadlock Prevention esource allocation rules prevent deadlock by prevent one of the four conditions required for deadlock from occurring Mutual exclusion Hold and wait No preemption ircular Wait Approach 4 Deadlock Prevention Attacking the Mutual Exclusion ondition Not feasible in general Some devices/resource are intrinsically not shareable. 4 44 Attacking the Hold and Wait ondition equire processes to request resources before starting a process never has to wait for what it needs Issues may not know required resources at start of run not always possible also ties up resources other processes could be using Variations: process must give up all resources if it would block hold a resource then request all immediately needed prone to starvation Attacking the No Preemption ondition This is not a viable option onsider a process given the printer halfway through its job now forcibly take away printer!!?? 45 46 Attacking the ircular Wait ondition (a) (b) Numerically ordered resources 47 Attacking the ircular Wait ondition The displayed deadlock cannot happen If A requires, it must acquire it before acquiring Note: If B has, all higher numbered resources must be free or held by processes who doesn t need esources ordering is a common technique in practice!!!!! A B 48 8

Summary of approaches to deadlock prevention ondition Mutual Exclusion Hold and Wait No Preemption ircular Wait Approach Not feasible equest resources initially Take resources away Order resources Nonresource Deadlocks Possible for two processes to deadlock each is waiting for the other to do some task an happen with semaphores each process required to do a down() on two semaphores (mutex and another) if done in wrong order, deadlock results 49 5 Starvation Starvation is where the overall system makes progress, but one or more processes never make progress. Example: An algorithm to allocate a resource may be to give to shortest job first Works great for multiple short jobs in a system May cause long job to be postponed indefinitely, even though not blocked Solution: First-come, first-serve policy 5 9