Deadlock Prevention. CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han

Similar documents
Deadlock. Operating Systems. Autumn CS4023

The deadlock problem

Last Class: Monitors. Real-world Examples

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

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.

The Deadlock Problem (1)

CS370 Operating Systems

Chapter 8: Deadlocks. The Deadlock Problem

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

Deadlocks. Dr. Yingwu Zhu

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

OPERATING SYSTEMS. Deadlocks

Deadlock and Starvation

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

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

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

CMSC 412. Announcements

System Model. Types of resources Reusable Resources Consumable Resources

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

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.

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

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

Deadlocks. Prepared By: Kaushik Vaghani

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

Chapter 7: Deadlocks

CS370 Operating Systems

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

More on Synchronization and Deadlock

Potential Deadlock Example

Deadlock. Concurrency: Deadlock and Starvation. Reusable Resources

Bridge Crossing Example

Chapter 7: Deadlocks

CS420: Operating Systems. Deadlocks & Deadlock Prevention

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

Deadlocks. Deadlock in Resource Sharing Environment. CIT 595 Spring Recap Example. Representing Deadlock

Chapter 7: Deadlocks

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

The Deadlock Problem

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

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

The Deadlock Problem

Chapter 8: Deadlocks

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

CS370 Operating Systems

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

The Deadlock Problem

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

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

Deadlocks. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

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

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

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

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

Chapter 6 Concurrency: Deadlock and Starvation

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

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

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

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

Lecture 7 Deadlocks (chapter 7)

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

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

Principles of Operating Systems

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

Last Class: Synchronization Problems. Need to hold multiple resources to perform task. CS377: Operating Systems. Real-world Examples

Chapter 8: Deadlocks. The Deadlock Problem

Chapter 7: Deadlocks

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

CS307 Operating Systems Deadlocks

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

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

Chapter 7: Deadlocks 1

Introduction to Deadlocks

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

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

Deadlock. Only one process can use the resource at a time but once it s done it can give it back for use by another process.

UNIT-3 DEADLOCKS DEADLOCKS

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

CS370 Operating Systems

Operating Systems ECE344. Ding Yuan

Concurrency: Deadlock and Starvation. Chapter 6

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

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

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

Fig Bridge crossing - deadlock

Module 7: Deadlocks. The Deadlock Problem

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

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

Chapter 6. Deadlock. (A Quick Introduction)

Principles of Operating Systems

Chapter 7: Deadlocks CS370 Operating Systems

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

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

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

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

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

CS307: Operating Systems

Chapter 8: Deadlocks. Operating System Concepts with Java

Contents. Chapter 8 Deadlocks

Last Class: Synchronization Problems!

Transcription:

Deadlock Prevention CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han

Announcements HW #3 is due Friday Feb. 25 extra office hours Thursday 1 pm - post this PA #2 assigned, due Thursday March 17 Midterm is Thursday March 10 Midterm review is Tuesday March 8 Read chapter 10

From last time... We discussed: Dining Philosophers Problem - deadlock! monitors high-level synchronization primitives don t have to explicitly P() and V() augmented with condition variables monitor-based solution to Dining Philosophers problem

Deadlock saw earlier that semaphores provide mutual exclusion, but can introduce deadlock 2 process, each desires a resource locked by the other process can occur easily due to programming errors, e.g. by switching order of P and V, etc. Even if no obvious programming errors, deadlock can occur deadlock is difficult to anticipate by a single thread, because the code looks fine, and deadlock is a higher-level concept that involves the distributed behavior of multiple processes/threads deadlock is difficult to anticipate, detect, reproduce, prevent, avoid, and recover from

Deadlock A set of processes is in a deadlock state when every process in the set is waiting for an event (e.g. release of a resource) that can only be caused by another process in the set multithreaded programs are good candidates for deadlock thread-thread deadlock within a process thread-thread deadlock across processes

Deadlock Detection Modeling deadlock: to use a resource, a process must 1. request() a resource -- must wait until it s available 2. use() or hold() a resource 3. release() a resource thus, we have resources and processes Most of the following discussion will focus on reusable resources Resources Buffer1... BufferN File F Disk D P1 P2 P3 Processes P1 holds Buffer 1 and File F P2 holds Buffer N P3 holds Disk D

Deadlock Detection a resource allocation graph can be used to model deadlock try to represent deadlock by a directed graph D(V,E), consisting of vertices V: namely processes and resources and edges E: a request() for a resource R j by a process P i is signified by a directed arrow from process P i R j a process P i will hold() a resource R j via a directed arrow R j P i

Deadlock Detection Example 1: P1 holds an instance of resource R2, and is requesting resource R1 P2 holds R1 and an instance of R2, and requests R3 P3 holds R3 There is no deadlock if the graph contains no cycles or loops, then there is no deadlock P1 R1 P2 R3 P3 R2 R4

Deadlock Detection Example 2: same graph as before, except now P3 requests an instance of R2 Deadlock occurs! P3 requests R2, which is held by P2, which requests R3, which is held by P3 - this is a loop P 3 R 2 P 2 R 3 P 3 If P1 could somehow release an instance of R2, then we could break the deadlock But P1 is part of a second loop: P 3 R 2 P 1 R 1 P 2 R 3 P 3 So P1 can t release its instance of R2 if the graph contains cycles or loops, then there may be the possibility of deadlock but does a loop guarantee that there is deadlock? P1 R1 P2 R3 P3 R2

Deadlock Detection Example 3: there is a loop: P 1 R 1 P 3 R 2 P 1 In this case, there is no deadlock either P2 can release an instance of R1, or P4 can release an instance of R2 this breaks any possible deadlock cycle if the graph contains cycles or loops, then there may be the possibility of deadlock, but this is not a guarantee of deadlock P1 R1 R2 P3 P2 P4

Necessary Conditions for Deadlock Deadlock can arise if the following 4 conditions hold simultaneously: 1. Mutual exclusion at least 1 resource is held in a non-sharable mode. Other requesting processes must wait until the resource is released 2. Hold and wait a process may hold a resource while request (and waiting for) another one 3. No preemption resources cannot be preempted and can only be released by the process holding it, after the process is finished. No OS intervention is allowed. A process cannot withdraw its request. 4. Circular wait A set of waiting processes {P 0,..., P n-1 } must exist such that Pi waits for a resource held by P (i+1)%n

Approaches to Handling Deadlocks Prevention provide methods to guarantee that at least 1 of the 4 necessary conditions for deadlock does not hold Avoidance the OS is given advanced information about which process requests which resource when this is used to determine whether the OS can satisfy the resource requests without causing deadlock Detection and Recovery Ignore and Pretend this is the most common approach, based on the assumption that deadlock is relatively infrequent UNIX and Windows use this approach

Deadlock Prevention Prevent the mutual exclusion condition from coming true This is opposite of our original goal, which was to provide mutual exclusion. Also, many resources are non-sharable and must be accessed in a mutually exclusive way example: a printer should print a file X to completion before printing a file Y. a printer should not print half of file X, and then print the first half of file Y on the same paper thus, it is unrealistic to prevent mutual exclusion

Deadlock Prevention Prevent the hold and wait condition from coming true prevent a process from holding resources and requesting others Solution I: request all resources at process creation Solution II: release all held resources before requesting a set of new ones simultaneously Example: a process reads from the DVD drive and writes the file to disk, sorts the file, then sends the file to the printer Solution I: request the DVD drive, disk, and printer at process creation Solution II: break the task down into wholly contained nondependent pieces obtain the DVD and disk together for the file transfer, then release both together next obtain the disk and printer together for the printing operation, then release both together

Deadlock Prevention Disadvantages of Hold-and-wait solutions don t know in advance all resources needed poor resource utilization a process that is holding multiple resources for a long time may only need each resource for a short time during execution possible starvation a process that needs several popular resources simultaneously may have to wait a very long time

Deadlock Prevention Prevent the No Preemption condition from coming true allow resources to be preempted Policy I: If a Process X requests a held resource, then all resources currently held by X are released. X is restarted only when it can regain all needed resources Policy II: If a process X requests a resource held by process Y, then preempt the resource from process Y, but only if Y is waiting on another resource. Otherwise, X must wait. the idea is if Y is holding some resources but is waiting on another resource, then Y has no need to keep holding its resources since Y is suspended Disadvantages: these policies don t apply to all resources, e.g. printers should not be prempted while in the middle of printing, disks should not be preempted while in the middle of writing a block of data can result in unexpected behavior of processes, since an application developer may not know a priori which policy is being used

Deadlock Prevention Prevent the circular wait condition from coming true Solution I: a process can only hold 1 resource at a time disadvantage: in some cases, a process needs to hold multiple resources to accomplish a task Solution II: impose a total ordering of all resource types and require each process to request resources in increasing order this prevents a circular wait - see next slide

Deadlock Prevention Example of preventing circular waits using ordering: Order all resources into a list: R1, R2,..., Rm, where R1 < R2 <... < Rm tape drive = R1 disk drive = R2 printer = R10 Impose the rule that a process holding R i can only request R j if R j > R i If a process P holds some R k and requests R j such that R j < R k, then the process must release all such R k, acquire R j, then reacquire R k can lead to poor performance

Deadlock Prevention Applying ordering of resources to break circular waiting in the Dining Philosophers Problem R1 < R2 < R3 < R4 < R5 Process P1 requests R1, then R2, proceeding Right to Left Process P2 requests R2, then R3, proceeding Right to Left... Process P5 requests R1, then R5, proceeding Left then Right due to ordering thus, P5 blocks on R1, not R5, which breaks any possibility of a circular deadlock - why? P1 P2 R2 R1 P5 R3 R5 R4 P3 P4