CSE 451: Operating Systems Winter Deadlock. Gary Kimura

Similar documents
Operating Systems. Deadlock. Lecture 7 Michael O Boyle

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

More on Synchronization and Deadlock

The Deadlock Problem

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

Bridge Crossing Example

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

CS370 Operating Systems

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. Prescribed Text Book. Operating System Principles, Seventh Edition. Abraham Silberschatz, Peter Baer Galvin and Greg Gagne

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

Quiz Answers. CS 537 Lecture 9 Deadlock. What can go wrong? Readers and Writers Monitor Example

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

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 8 th Edition,

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

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

Last Class: Monitors. Real-world Examples

The deadlock problem

Chapter 8: Deadlocks. The Deadlock Problem

Chapter 7: Deadlocks

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

Chapter 3: Deadlocks

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

Chapter 8: Deadlocks. Operating System Concepts with Java

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

Concurrency Issues. Past lectures: What about coordinated access across multiple objects? Today s lecture:

CS370 Operating Systems

Chapter 3. Deadlocks

CS420: Operating Systems. Deadlocks & Deadlock Prevention

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

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

Fig Bridge crossing - deadlock

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

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

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

DUH! Deadlocks. Concurrency Issues. The TENEX Case. If a process requests all systems buffers, operator console tries to print an error message

CS370 Operating Systems

Outlook. Deadlock Characterization Deadlock Prevention Deadlock Avoidance

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

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

COMP 346 WINTER Tutorial 9 DEADLOCK

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

Operating Systems: William Stallings. Starvation. Patricia Roy Manatee Community College, Venice, FL 2008, Prentice Hall

Operating Systems ECE344. Ding Yuan

Chapter 7: Deadlocks CS370 Operating Systems

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

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

Module 7: Deadlocks. The Deadlock Problem

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

UNIT-3 DEADLOCKS DEADLOCKS

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

Potential Deadlock Example

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

CSE 4/521 Introduction to Operating Systems. Lecture 12 Main Memory I (Background, Swapping) Summer 2018

Chapter 6. Deadlock. (A Quick Introduction)

Basics of Deadlock Theory. Deadlocks

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

Concurrency: Deadlock and Starvation. Chapter 6

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

Chapter 3. Deadlocks

Deadlock. Readings and References. Simple Traffic Gridlock Example. Deadlock. Reading. Other References. CSE 410, Spring 2006 Computer Systems

CS 318 Principles of Operating Systems

Deadlocks. Copyright : University of Illinois CS 241 Staff 1

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

Deadlock CS 241. March 19, University of Illinois

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

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

CSC Operating Systems Fall Lecture - XII Deadlocks - III. Tevfik Ko!ar. Louisiana State University. October 6 th, 2009

Deadlock. Concurrency: Deadlock and Starvation. Reusable Resources

Course Description: This course includes the basic concepts of operating system

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

TDDB68 + TDDD82. Lecture: Deadlocks

Deadlock 1 Chapter 6

Chapter 7: Deadlocks 1

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

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

CS450/550 Operating Systems

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

Deadlocks Detection and Avoidance. Prof. Sirer CS 4410 Cornell University

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

CMSC 412. Announcements

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

Deadlocks. Dr. Yingwu Zhu

Chapter 3: Deadlocks. Chapter 3

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

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.

Principles of Operating Systems

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

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 7: Deadlocks. Chapter 7: Deadlocks. System Model. Chapter Objectives

Lecture 9: Midterm Review

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

Concurrency: Deadlock and Starvation

Frequently asked questions from the previous class survey

CSE 306/506 Operating Systems Deadlock. YoungMin Kwon

CS370 Operating Systems

Transcription:

CSE 451: Operating Systems Winter 2013 Deadlock Gary Kimura

2

Definition A thread is deadlocked when it s waiting for an event that can never occur I m waiting for you to clear the intersection, so I can proceed but you can t move until he moves, and he can t move until she moves, and she can t move until I move thread A is in critical section 1, waiting for access to critical section 2; thread B is in critical section 2, waiting for access to critical section 1 I m trying to book a vacation package to Tahiti air transportation, ground transportation, hotel, side-trips. It s all-or-nothing one high-level transaction with the four databases locked in that order. You re trying to do the same thing in the opposite order. 3

1. Mutual Exclusion Requirements - Resource owned by one thread 2. Hold and Wait - Thread may hold a resource while waiting 3. No Preemption - Ownership is never transferred 4. Circular Wait - Irreducible cycle in hold/wait graph 4

Resource graph A deadlock exists if there is an irreducible cycle in the resource graph (such as the one above) 5

Graph reduction A graph can be reduced by a thread if all of that thread s requests can be granted in this case, the thread eventually will free all resources and not be waiting on any all arcs (allocations) to it in the graph are deleted Miscellaneous theorems (Holt, Havender): There are no deadlocked threads iff the graph is completely reducible The order of reductions is irrelevant (Detail: resources with multiple units) 6

Resource allocation graph with no cycle What would cause a deadlock? Silberschatz, Galvin and Gagne 2002 7

Resource allocation graph with a deadlock Silberschatz, Galvin and Gagne 2002 8

Resource allocation graph with a cycle but no deadlock Silberschatz, Galvin and Gagne 2002 9

Approaches to Deadlock Break one of the four required conditions Mutual Exclusion? Hold and Wait? No Preemption? Circular Wait? Broadly classified as: Prevention (static), or Avoidance (dynamic), or detection (and recovery) 10

Hold and Wait Prevention (static) each thread obtains all resources at the beginning; blocks until all are available drawback? Circular Wait resources are ordered; each thread obtains them in sequence (which means acquiring some before they are actually needed) why does this work? pros and cons? 11

Circular Wait Avoidance (dynamic) each thread states its maximum claim for every resource type system runs the Banker s Algorithm at each allocation request Banker incredibly conservative if I were to allocate you that resource, and then everyone were to request their maximum claim for every resource, could I find a way to allocate remaining resources so that everyone finished? More on this in a moment 12

every once in a while, check to see if there s a deadlock how? if so, eliminate it how? Detection and recovery 13

Avoidance: Banker s Algorithm example When a request is made pretend you granted it pretend all other legal requests were made can the graph be reduced? if so, allocate the requested resource if not, block the thread 14

1. I request a pot Pots Me You 1 pot 2 pans 2 pots 1 pan Pans 15

Allocation is OK; there is a way for me to complete, and then you can complete Pots Me You 1 pot 2 pans 2 pots 1 pan Pans 16

2. You request a pot Pots Me You 1 pot 2 pans 2 pots 1 pan Pans 17

Allocation is OK; there is a way for me to complete, and then you can complete Pots Me You 1 pot 2 pans 2 pots 1 pan Pans 18

3a. You request a pan Pots Me You 1 pot 2 pans 2 pots 1 pan Pans 19

NO! Both of us might be unable to complete! Pots Me You 1 pot 2 pans 2 pots 1 pan Pans 20

3b. I request a pan Pots Me You 1 pot 2 pans 2 pots 1 pan Pans 21

Allocation is OK; there is a way for me to complete, and then you can complete Pots Me You 1 pot 2 pans 2 pots 1 pan Pans 22

Microsoft SQL Server Current practice The SQL Server Database Engine automatically detects deadlock cycles within SQL Server. The Database Engine chooses one of the sessions as a deadlock victim and the current transaction is terminated with an error to break the deadlock. Oracle As Microsoft SQL Server, plus Multitable deadlocks can usually be avoided if transactions accessing the same tables lock those tables in the same order... For example, all application developers might follow the rule that when both a master and detail table are updated, the master table is locked first and then the detail table. 23

Windows internals (Linux no different) the NT kernel architecture is a deadlock minefield. With the multi-threaded re-entrant kernel there is plenty of deadlock potential. Lock ordering is great in theory, and NT was originally designed with mutex levels, but they had to be abandoned. Inside the NT kernel there is a lot of interaction between memory management, the cache manager, and the file systems, and plenty of situations where memory management (maybe under the guise of its modified page writer) acquires its lock and then calls the cache manager. This happens while the file system calls the cache manager to fill the cache which in turn goes through the memory manager to fault in its page. And the list goes on. Enhancements to semaphores for file systems: Reacquire by owning thread Test for ownership before acquiring 24

Summary Deadlock is bad! We can deal with it either statically (prevention) or dynamically (avoidance and detection) In practice, you ll encounter lock ordering, periodic deadlock detection/correction, and minefields 25