Deadlock cs550 Operating Systems David Monismith.

Slides:



Advertisements
Similar presentations
Parallel Programming – Barriers, Locks, and Continued Discussion of Parallel Decomposition David Monismith Jan. 27, 2015 Based upon notes from the LLNL.
Advertisements

Deadlock Prevention, Avoidance, and Detection
Deadlock and Starvation
Deadlocks Operating Systems (234123) Spring 2013 Deadlocks Dan Tsafrir (13/5/2013) Partially based on slides by Hagit Attiya OS (234123) - spring 2013.
Operating Systems Lecture Notes Deadlocks Matthew Dailey Some material © Silberschatz, Galvin, and Gagne, 2002.
Deadlock Prevention, Avoidance, and Detection.  The Deadlock problem The Deadlock problem  Conditions for deadlocks Conditions for deadlocks  Graph-theoretic.
DEADLOCK. Contents  Principles of deadlock  Deadlock prevention  Deadlock detection.
6. Deadlocks 6.1 Deadlocks with Reusable and Consumable Resources
Chapter 7: Deadlocks.
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Deadlock Emery Berger and Mark Corner University of Massachusetts.
Chapter 6 Concurrency: Deadlock and Starvation
Chapter 3 Deadlocks TOPICS Resource Deadlocks The ostrich algorithm
MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 6 Deadlocks Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All.
Avishai Wool lecture Introduction to Systems Programming Lecture 5 Deadlocks.
Deadlocks CS 3100 Deadlocks1. The Deadlock Problem A set of blocked processes each holding a resource and waiting to acquire a resource held by another.
10 Deadlock Example Process 1 Process 2 Resource 1 Resource 2 Process holds the resource Process requests the resource.
Deadlocks. 2 System Model There are non-shared computer resources –Maybe more than one instance –Printers, Semaphores, Tape drives, CPU Processes need.
Deadlock CSCI 444/544 Operating Systems Fall 2008.
CS 450 OPERATING SYSTEMS DEADLOCKS Manju Muralidharan Priya.
The ‘deadlock’ conditions Reviewing some key points concerning the potential for ‘deadlock’ in an operating system.
OS Spring 2004 Concurrency: Principles of Deadlock Operating Systems Spring 2004.
Chapter 7 – Deadlock and Indefinite Postponement
OS Fall’02 Concurrency: Principles of Deadlock Operating Systems Fall 2002.
Chapter 6 Concurrency: Deadlock and Starvation
Chapter 6 Deadlocks Resources Introduction Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved
Silberschatz, Galvin and Gagne  Operating System Concepts Deadlock and Starvation Deadlock – two or more processes are waiting indefinitely for.
Deadlock Questions answered in this lecture: What are the four necessary conditions for deadlock? How can deadlock be prevented? How can deadlock be avoided?
Chapter 7 – Deadlock (Pgs 283 – 306). Overview  When a set of processes is prevented from completing because each is preventing the other from accessing.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-6 Deadlocks Department of Computer Science and Software Engineering.
Operating Systems (OS)
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock.
CIS Operating Systems Deadlock Professor Qiang Zeng Fall 2015.
This Time - Deadlock Definition Conditions for deadlocks
 The Deadlock Problem  System Model  Deadlock Characterization  Methods for Handling Deadlocks  Deadlock Prevention  Deadlock Avoidance  Deadlock.
CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:
Chapter 7 Deadlocks. 7.1 Introduction Deadlock Common approaches to deal with deadlock – Prevention – Avoidance – Detection and recovery.
Deadlocks System Model RAG Deadlock Characterization
CS333 Intro to Operating Systems Jonathan Walpole.
Lecture 12 Handling Deadlock – Prevention, avoidance and detection.
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings.
Deadlocks Mark Stanovich Operating Systems COP 4610.
Chapter 8 Deadlocks. Objective System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance Deadlock Detection.
Deadlocks Introduction to Operating Systems: Module 7.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 6: Deadlocks.
Deadlocks Copyright ©: University of Illinois CS 241 Staff1.
Slide 10-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10.
Operating Systems Unit 4: – Dining Philosophers – Deadlock – Indefinite postponement Operating Systems.
Silberschatz, Galvin and Gagne ©2009 Edited by Khoury, 2015 Operating System Concepts – 9 th Edition, Chapter 7: Deadlocks.
Rensselaer Polytechnic Institute CSCI-4210 – Operating Systems David Goldschmidt, Ph.D.
Deadlock CS Introduction to Operating Systems.
7: Deadlocks1 OPERATING SYSTEMS DEADLOCKS. 7: Deadlocks2 What Is In This Chapter? What is a deadlock? Staying Safe: Preventing and Avoiding Deadlocks.
Deadlock. Examples You can't get a job without experience; you can't get experience without a job. A set of blocked processes each holding a resource.
Process Management Deadlocks.
Chapter 7: Deadlocks.
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Concurrency: Deadlock and Starvation
Deadlock Detection & recovery
ITEC 202 Operating Systems
Chapter 7 – Deadlock and Indefinite Postponement
Operating System: DEADLOCKS
Lecture 18: Deadlock: Conditions, Detection and Avoidance (cont.)
Deadlocks Definition A set of processes is in a Deadlock state when every process in the set is waiting for an event that can only be caused by another.
DPNM Lab. Dept. of CSE, POSTECH
MODERN OPERATING SYSTEMS Third Edition ANDREW S
DEADLOCK.
OPERATING SYSTEMS DEADLOCKS.
Chapter 7: Deadlocks.
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Presentation transcript:

Deadlock cs550 Operating Systems David Monismith

Deadlock Four requirements for deadlock Hold and wait - process holds resource while waiting for more resources Mutual Exclusion - resource can't be shared Circular Wait - processes want something that another process has. No preemption - can't interrupt a process's hold on a resource

Resource allocation graph Circles represent processes Rectangles represent resources Dots within the resource represent the number of available resources of that type Arrows from resources (rectangle) to process (circle) indicates resource ownership Arrows from process (circle) to resource (rectangle) indicates need/request

o We can show deadlock is possible by finding an example of deadlock and showing all 4 requirements exist We can show deadlock does not exist by proving that one of the requirements does not exist. o We can show deadlock does not exist by proving that one of the requirements does not exist. Example

Example : Dining Philosophers  Five students eating at Joy Wok with chopsticks  Only five chopsticks available.  A student needs two chopsticks to eat.  Chopsticks are situated between students.  Students can't move from their positions at the table.  Students alternate between thinking and eating.

\ (S1) |(S2) / (S3) Rice (S4) / (S5) \ A possible solution: Students always reach right first. Example : Dining Philosophers (Contd..) (S1)-Req.-->[R2]--Acq.-->(S2)--Req.-->[R3]--Acq.-->(S3)--Req.-->[R4]--Acq.-->(S4)--Req.--+ ^ | | | Req.----(S5)<----Acq.---[R5]<

How to deal with deadlock? Ignore it! Detect and recover from it! Avoid it! (make deadlock impossible) Prevent it! (short circuit one of the four conditions preferably hold and wait or circular wait) We need mutual exclusion and prefer not to preempt necessary resources

Many OSes (if not all) allow for deadlock to occur. It is easy to reboot. Detection can also be used. How to detect? Keep a version of the resource allocation graph available in OS memory. Update graph based upon resource requests and releases Asynchronous graph algorithms can be used to look for cycles on the RAG Break the cycle! (we can terminate processes or preempt resources) We can look for idle programs but this rarely works

Deadlock Deadlock will occur with the dining philosophers problem using the following pseudocode Acquire left fork (or right) Acquire right fork Start eating if possible After eating, release forks Do work (start thinking) Prevention Make one condition for deadlock impossible Mutual exclusion Hold and wait Circular Wait No preemption

Our focus will be on hold and wait and circular wait Two strategies exist for hold and wait Process must acquire all resources it needs before starting  good for batch systems Process must release all resources before requesting new resources  good for interactive systems Let the philosophers acquire forks only if both are available

Pseudocode while true Acquire semaphore 1. Check if both forks are available and continue, otherwise wait. 2. Attempt to acquire the left fork 3. Attempt to acquire the right fork 4. Eat for a specified time period and release forks Release semaphore Think for a specified time period end while

We can also disallow circular wait Need to draw circular wait here We can assign ordering to resources Give each fork a number that is unique We can prevent deadlock with ordering of forks Check the index values of the forks Require the forks to always be acquired in order of the index values Circular Wait

Philosopher code 1. Check if the index value of the left fork is less than the index value of the right fork. If true, do 2 then 3. Otherwise, do 3 then Attempt to acquire the left chopstick 3. Attempt to acquire the right chopstick. 4. Eat for specified time period 5. Release forks 6. Think for a specified time period How could we program these in Java? In C?