Starvation and Deadlock

Slides:



Advertisements
Similar presentations
Chapter 7: Deadlocks.
Advertisements

ICS Principles of Operating Systems Lectures 8 and 9 - Deadlocks Prof. Dmitri V. Kalashnikov dvk ics.uci.edu Slides © Prof. Nalini Venkatasubramanian.
Deadlock and Starvation
Operating Systems Lecture Notes Deadlocks Matthew Dailey Some material © Silberschatz, Galvin, and Gagne, 2002.
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community.
Deadlocks Today Resources & deadlocks Dealing with deadlocks Other issues Next Time Memory management.
Chapter 7: Deadlocks.
Chapter 6 Concurrency: Deadlock and Starvation
Chapter 6 Concurrency: Deadlock and Starvation
 2004 Deitel & Associates, Inc. All rights reserved. Chapter 7 – Deadlock and Indefinite Postponement Outline 7.1 Introduction 7.2Examples of Deadlock.
Deadlocks Andy Wang Operating Systems COP 4610 / CGS 5765.
1 Deadlocks Chapter Resource 3.2. Introduction to deadlocks 3.3. The ostrich algorithm 3.4. Deadlock detection and recovery 3.5. Deadlock avoidance.
Deadlock Chapter 3 R1 R2 P2P1 Allocated Requested.
Deadlocks. 2 System Model There are non-shared computer resources –Maybe more than one instance –Printers, Semaphores, Tape drives, CPU Processes need.
Chapter 7: Deadlocks. 7.2 Chapter Objectives To develop a description of deadlocks, which prevent sets of concurrent processes from completing their tasks.
Modified from Silberschatz, Galvin and Gagne Lecture 13 Chapter 7: Deadlocks.
Deadlock CSCI 444/544 Operating Systems Fall 2008.
CS 450 OPERATING SYSTEMS DEADLOCKS Manju Muralidharan Priya.
02/18/2008CSCI 315 Operating Systems Design1 Deadlock Notice: The slides for this lecture have been largely based on those accompanying the textbook Operating.
Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks
Chapter 7 – Deadlock and Indefinite Postponement
1 Concurrency: Deadlock and Starvation Chapter 6.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Bridge Crossing Example Traffic only in one direction. Each section.
Chapter 6 Concurrency: Deadlock and Starvation
Concurrency: Deadlock and Starvation Chapter 6. Goal and approach Deadlock and starvation Underlying principles Solutions? –Prevention –Detection –Avoidance.
1 Deadlock Solutions CS 241 March 28, 2012 University of Illinois.
Deadlock Chapter 3 Thursday, February 22, Today’s Schedule Assignment #4 from Chapter 3 posted Deadlock - Chapter 3  Skip multiple resources (3.4.2.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 8: Deadlocks System Model Deadlock Characterization Methods for Handling Deadlocks.
Chapter 7 – Deadlock (Pgs 283 – 306). Overview  When a set of processes is prevented from completing because each is preventing the other from accessing.
1 Deadlocks Chapter Resource 3.2. Introduction to deadlocks 3.4. Deadlock detection and recovery 3.5. Deadlock avoidance 3.6. Deadlock prevention.
1 Deadlocks 2 Resources Examples of computer resources –printers –tape drives –tables Processes need access to resources in reasonable order Suppose.
1 Deadlocks Chapter Resource 3.2. Introduction to deadlocks 3.3. The ostrich algorithm 3.4. Deadlock detection and recovery 3.5. Deadlock avoidance.
Operating Systems 软件学院 高海昌 Operating Systems Gao Haichang, Software School, Xidian University 22 Contents  1. Introduction** 
Operating Systems Part III: Process Management (Deadlocks)
1 Deadlocks Chapter Resource 3.2. Introduction to deadlocks 3.3. The ostrich algorithm 3.4. Deadlock detection and recovery 3.5. Deadlock avoidance.
Cosc 4740 Chapter 6, Part 4 Deadlocks. The Deadlock Problem A set of blocked processes each holding a resource and waiting to acquire a resource held.
MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 6 Deadlocks Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All.
This Time - Deadlock Definition Conditions for deadlocks
Operating Systems (CS 340 D) Dr. Abeer Mahmoud Princess Nora University Faculty of Computer & Information Systems Computer science Department.
CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:
CS 346 – Chapter 7 Deadlock –Properties –Analysis: directed graph Handle –Prevent –Avoid Safe states and the Banker’s algorithm –Detect –Recover.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 14, 2005 Chapter 7: Deadlocks The Deadlock.
Deadlocks System Model RAG Deadlock Characterization
CS333 Intro to Operating Systems Jonathan Walpole.
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings.
Deadlocks Mark Stanovich Operating Systems COP 4610.
Deadlocks.  Deadlocks: Occurs when threads are waiting for resources with circular dependencies Often involve nonpreemptable resources, which cannot.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Lecture 7 Operating Systems.
Operating Systems Unit VI Deadlocks and Protection Department of Computer Science Engineering and Information Technology.
Deadlock. Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock.
Deadlocks Introduction to Operating Systems: Module 7.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 6: Deadlocks.
Starvation and Deadlock. Another EventBarrier Example EventBarrier channel; void OutputThread { while (TRUE) { ComputeDataToSend(); channel.Wait(); SendData();
Deadlocks Copyright ©: University of Illinois CS 241 Staff1.
Operating Systems Unit 4: – Dining Philosophers – Deadlock – Indefinite postponement Operating Systems.
Copyright ©: Nahrstedt, Angrave, Abdelzaher1 Deadlock.
Lecture 6 Deadlock 1. Deadlock and Starvation Let S and Q be two semaphores initialized to 1 P 0 P 1 wait (S); wait (Q); wait (Q); wait (S);. signal (S);
Deadlock Operating Systems (CC2011NI) -Mr. Pranoy Man Pradhan.
Synchronization Deadlocks and prevention
CSE 120 Principles of Operating
ITEC 202 Operating Systems
Introduction to Operating Systems
Chapter 7 Deadlock.
Chapter 7: Deadlocks.
Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks
Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks
CSE 153 Design of Operating Systems Winter 2019
Introduction to Deadlocks
Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks
Presentation transcript:

Starvation and Deadlock

Starvation Example: a one-lane bridge. The reader/writer lock example illustrates starvation: under load, a writer will be stalled forever by a stream of readers. Example: a one-lane bridge. Wait for oncoming car to exit the bridge before entering. Repeat as necessary. Problem: a “writer” may never be able to cross if faced with a continuous stream of oncoming “readers”. Solution: some reader must politely stop before entering, even though it is not forced to wait by oncoming traffic. Use extra synchronization to control the lock scheduling policy. Complicates the implementation: optimize only if necessary.

Deadlock Deadlock is closely related to starvation. Processes wait forever for each other to wake up and/or release resources. Example: traffic gridlock. The difference between deadlock and starvation is subtle. With starvation, there always exists a schedule that feeds the starving party. The situation may resolve itself…if you’re lucky. Once deadlock occurs, it cannot be resolved by any possible future schedule. …though there may exist schedules that avoid deadlock.

Dining Philosophers N processes share N resources resource requests occur in pairs random think times hungry philosopher grabs a fork ...and doesn’t let go ...until the other fork is free ...and the linguine is eaten D B A C 1 2 3 4 while(true) { Think(); AcquireForks(); Eat(); ReleaseForks(); }

Four Preconditions for Deadlock Four conditions must be present for deadlock to occur: 1. Non-preemptability. Resource ownership (e.g., by threads) is non-preemptable. Resources are never taken away from the holder. 2. Exclusion. Some thread cannot acquire a resource that is held by another thread. 3. Hold-and-wait. Holder blocks awaiting another resource. 4. Circular waiting. Threads acquire resources out of order.

Resource Graphs Given the four preconditions, some schedules may lead to circular waits. Deadlock is easily seen with a resource graph or wait-for graph. The graph has a vertex for each process and each resource. If process A holds resource R, add an arc from R to A. If process A is waiting for resource R, add an arc from A to R. The system is deadlocked iff the wait-for graph has at least one cycle. Sn A A grabs fork 1 and waits for fork 2. B grabs fork 2 and waits for fork 1. 1 2 B assign request

Not All Schedules Lead to Collisions The scheduler chooses a path of the executions of the threads/processes competing for resources. Synchronization constrains the schedule to avoid illegal states. Some paths “just happen” to dodge dangerous states as well. What is the probability that philosophers will deadlock? How does the probability change as: think times increase? number of philosophers increases?

Resource Trajectory Graphs Resource trajectory graphs (RTG) depict the scheduler’s “random walk” through the space of possible system states. Sm Sn So RTG for N processes is N-dimensional. Process i advances along axis I. Each point represents one state in the set of all possible system states. cross-product of the possible states of all processes in the system (But not all states in the cross-product are legally reachable.)

RTG for Two Philosophers A1 A2 R2 R1 1 2 Y Sn Sm R2 R1 X Sn A1 2 1 Sm A2 (There are really only 9 states we care about: the important transitions are allocate and release events.)

Two Philosophers Living Dangerously X R1 2 1 A1 Y ??? A2

The Inevitable Result X Y A1 A2 R2 R1 R2 R1 2 1 A1 A2 no legal transitions out of this deadlock state

Dealing with Deadlock 1. Ignore it. “How big can those black boxes be anyway?” 2. Detect it and recover. Traverse the resource graph looking for cycles before blocking any customer. If a cycle is found, preempt: force one party to release and restart. 3. Prevent it statically by breaking one of the preconditions. Assign a fixed partial ordering to resources; acquire in order. Use locks to reduce multiple resources to a single resource. Acquire resources in advance of need; release all to retry. 4. Avoid it dynamically by denying some resource requests. Banker’s algorithm

Extending the Resource Graph Model Reasoning about deadlock in real systems is more complex than the simple resource graph model allows. Resources may have multiple instances (e.g., memory). Cycles are necessary but not sufficient for deadlock. For deadlock, each resource node with a request arc in the cycle must be fully allocated and unavailable. Processes may block to await events as well as resources. E.g., A and B each rely on the other to wake them up for class. These “logical” producer/consumer resources can be considered to be available as long as the producer is still active. Of course, the producer may not produce as expected.

Banker’s Algorithm The Banker’s Algorithm is the classic approach to deadlock avoidance for resources with multiple units. 1. Assign a credit limit to each customer. “maximum claim” must be stated/negotiated in advance 2. Reject any request that leads to a dangerous state. A dangerous state is one in which a sudden request by any customer(s) for the full credit limit could lead to deadlock. A recursive reduction procedure recognizes dangerous states. 3. In practice, this means the system must keep resource usage well below capacity to maintain a reserve surplus. Rarely used in practice.