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

Similar documents
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.

Chapter 3: Deadlocks

CS450/550 Operating Systems

Chapter 6. Deadlocks

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

Resources. Chapter 3. Deadlocks. Resources. Resources

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

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

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

Chapter 3: Deadlocks. Chapter 3

Chapter 6 - Deadlocks

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

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

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

Deadlocks. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

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

Frequently asked questions from the previous class survey

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

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

More on Synchronization and Deadlock

11 Resource Management Deadlock and Starvation

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

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

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

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

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

Chapter 6. Deadlock. (A Quick Introduction)

Deadlock and Starvation

Last Class: Monitors. Real-world Examples

Deadlock and Starvation

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

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

UNIT 4 DEADLOCKS 4.0 INTRODUCTION

Deadlock 1 Chapter 6

Operating Systems. Deadlocks

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. Copyright : University of Illinois CS 241 Staff 1

OPERATING SYSTEMS. Deadlocks

Chap. 3. Input/Output

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

Deadlock 1 Chapter 6

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

Operating Systems ECE344. Ding Yuan

Chapter 7: Deadlocks 1

Deadlocks. Operating Systems. Resources. Deadlocks

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

COMPUTER SCIENCE 4500 OPERATING SYSTEMS

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

Computer Science 4500 Operating Systems

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

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

CMPT 300 Introduction to Operating Systems

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

Concurrency: Deadlock and Starvation. Chapter 6

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.

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

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

Deadlock CS 241. March 19, University of Illinois

Operating Systems. Operating Systems Sina Meraji U of T

Back to synchronization

Deadlock. Concurrency: Deadlock and Starvation. Reusable Resources

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

UNIT:2. Process Management

Yet another synchronization problem

CSE 380 Computer Operating Systems

6. Concurrency: Deadlock

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

Deadlock. Disclaimer: some slides are adopted from Dr. Kulkarni s and book authors slides with permission 1

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

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

Outline. Deadlock. Examples, Conditions, Strategies. Deadlock Prevention. Deadlock Avoidance. Banker s algorithm

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.

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

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

The Deadlock Problem (1)

Chapter seven: Deadlock and Postponement

Fig Bridge crossing - deadlock

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

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

Deadlocks. Prepared By: Kaushik Vaghani

CS370 Operating Systems

CSE Opera+ng System Principles

Deadlock. Disclaimer: some slides are adopted from Dr. Kulkarni s and book authors slides with permission 1

Chapter 7: Deadlocks CS370 Operating Systems

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

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

Chapters 5 and 6 Concurrency

Chapter 8: Deadlocks. The Deadlock Problem

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

Deadlocks: Part I Prevention and Avoidance Yi Shi Fall 2017 Xi an Jiaotong University

Operating Systems. Deadlock. Lecturer: William Fornaciari Politecnico di Milano Homel.deib.polimi.

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

Deadlock. Operating Systems. Autumn CS4023

Operating Systems: Quiz2 December 15, Class: No. Name:

Transcription:

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 2 0 1 8

NON-RESOURCE DEADLOCKS Possible for two processes to deadlock each is waiting for the other to do some task Can happen with semaphores each process required to do a down() on two semaphores (mutex and another) if done in wrong order, deadlock results 2

INTRODUCTION TO DEADLOCKS Many processes require exclusive access to several resources. Suppose, for example, two processes each want to record a scanned document on a Blu-ray disc. Process A requests permission to use the scanner and is granted it. Process B is programmed differently and requests the Blu-ray recorder first and is also granted it. Now A asks for the Blu-ray recorder, but the request is suspended until B releases it. Unfortunately, instead of releasing the Bluray recorder, B asks for the scanner. At this point both processes are blocked and will remain so forever. This situation is called a deadlock.

INTRODUCTION TO DEADLOCKS In a database system, for example, a program may have to lock several records it is using, to avoid race conditions. If process A locks record R1 and process B locks record R2, and then each process tries to lock the other one s record, we also have a deadlock. Thus, deadlocks can occur on hardware resources or on software resources.

DEFINITION 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 5

RESOURCES A resource is anything that must be acquired, used, and released over the course of time. Resources can be hardware or software printers Database tables Resources can have a single or multiple instances 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 6

PREEMPTABLE VS. NONPREEMPTABLE RESOURCES Preemptable resources can be taken away from a process with no ill effects memory Nonpreemptable resources will cause the process to fail if taken away printer Deadlocks occur when processes are granted exclusive access to devices we refer to these devices generally as resources 7

PREEMPTABLE VS. NONPREEMPTABLE RESOURCES Consider, a system with 1 GB of user memory, one printer, and two 1-GB processes that each want to print something. Process A requests and gets the printer, then starts to compute the values to print. Before it has finished the computation, it exceeds its time quantum and is swapped out to disk. Process B now runs and tries, unsuccessfully as it turns out, to acquire the printer. Potentially, we now have a deadlock situation, because A has the printer and B has the memory, and neither one can proceed without the resource held by the other. Fortunately, it is possible to preempt (take away) the memory from B by swapping it out and swapping A in. Now A can run, do its printing, and then release the printer. No deadlock occurs. If a process has begun to burn a Blu-ray, suddenly taking the Blu-ray recorder away from it and giving it to another process will result in a garbled Blu-ray. Blu-ray recorders are not preemptable at an arbitrary moment

USING RESOURCES Sequence of events required to use a resource 1. request the resource 2. use the resource 3. release the resource Must wait if request is denied requesting process may be blocked may fail with error code 9

USING RESOURCES The order resources are acquired and released matters.

FOUR CONDITIONS FOR DEADLOCK 1. Mutual exclusion condition each resource assigned to 1 process or is available 2. Hold and wait condition process holding resources can request additional 3. No preemption condition previously granted resources cannot forcibly taken away 4. Circular wait condition must be a circular chain of 2 or more processes each is waiting for resource held by next member of the chain 11

DEADLOCK MODELING (1) Modeled with directed graphs resource R assigned to process A process B is requesting/waiting for resource S process C and D are in deadlock over resources T and U 12

DEADLOCK MODELING (2) How deadlock occurs A B C 13

DEADLOCK MODELING (3) How deadlock can be avoided 14

DEALING WITH DEADLOCKS Strategies for dealing with Deadlocks 1. just ignore the problem altogether 2. detection and recovery 3. dynamic avoidance careful resource allocation 4. prevention negating one of the four necessary conditions 15

THE OSTRICH ALGORITHM Pretend there is no problem Reasonable if deadlocks occur very rarely cost of prevention is high UNIX and Windows takes this approach It is a trade off between convenience correctness 16

DETECTION WITH ONE RESOURCE OF EACH TYPE (1) Note the resource ownership and requests A cycle can be found within the graph, denoting deadlock 17

DETECTION WITH ONE RESOURCE OF EACH TYPE (2) Data structures needed by deadlock detection algorithm 18

DETECTION WITH ONE RESOURCE OF EACH TYPE (3) 19

RECOVERY FROM DEADLOCK (1) Recovery through preemption take a resource from some other process depends on nature of the resource Recovery through rollback checkpoint a process periodically use this saved state restart the process if it is found deadlocked 20

RECOVERY FROM DEADLOCK (2) Recovery 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 21

DEADLOCK AVOIDANCE RESOURCE TRAJECTORIES Two process resource trajectories 22

SAFE AND UNSAFE STATES A safe state: from a safe state the system can guarantee that all processes will finish from an unsafe state, no such guarantee can be given. 23

DEADLOCK PREVENTION ATTACKING THE MUTUAL EXCLUSION CONDITION Impractical Some devices (such as printer) can be spooled Only daemon access the printer, only the printer daemon uses printer resource, and the daemon uses only the printer The whole file has to be sent to the daemon before it starts printing. Processes can deadlock on the spooling disk space. Principle: avoid assigning resource when not absolutely necessary as few processes as possible actually claim the resource 24

ATTACKING THE HOLD AND WAIT CONDITION Require processes to request ALL resources before starting a process never has to wait for what it needs Problems may not know required resources at start of run also ties up resources other processes could be using Variation: A process needing a new resource must release all currently held resources. then request them All at once when needed. 25

ATTACKING THE NO PREEMPTION CONDITION This is not a viable option Consider a process given the printer halfway through its job now forcibly take away printer Virtualizing the resource Adding an extra layer of indirection ( spooling disk space ) 26

ATTACKING THE CIRCULAR WAIT CONDITION (1) All resources are global numbering. A process is allowed to acquire resources in strictly increasing numerical order. A relaxed version: a process is NOT allowed to acquire resources with numbers below currently-held resources. 27

OTHER ISSUES TWO-PHASE LOCKING Phase One process tries to lock all records it needs, one at a time if needed record found locked, start over (no real work done in phase one) If phase one succeeds, it starts second phase, performing updates releasing locks Note similarity to requesting all resources at once Algorithm works where programmer can arrange program can be stopped, restarted 28

Most operating systems, including UNIX and Windows, basically just ignore the problem on the assumption that most users would prefer an occasional livelock (or even deadlock) to a rule restricting all users to one process, one open file, and one of everything. If these problems could be eliminated for free, there would not be much discussion. The problem is that the price is high, mostly in terms of putting inconvenient restrictions on processes. Thus, we are faced with an unpleasant trade-off between convenience and correctness. LIVELOCKS Incurred in most table data structures in the operating system, process table, i-node table.

DINING PHILOSOPHERS

DINING PHILOSOPHERS

STARVATION 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-served policy 32