CSE 120 Principles of Operating

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.
Concurrency: Deadlock and Starvation Chapter 6. Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate.
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.
1 CSC 539: Operating Systems Structure and Design Spring 2005 Process deadlock  deadlock prevention  deadlock avoidance  deadlock detection  recovery.
Deadlock Chapter 3 R1 R2 P2P1 Allocated Requested.
Deadlock April 19, 2000 Instructor: Gary Kimura Slides courtesy of Hank Levy.
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.
Deadlock CSCI 444/544 Operating Systems Fall 2008.
CS 153 Design of Operating Systems Spring 2015 Lecture 11: Scheduling & Deadlock.
Operating Systems Part III: Process Management (Deadlocks)
1 Deadlock. 2 Concurrency Issues Past lectures:  Problem: Safely coordinate access to shared resource  Solutions:  Use semaphores, monitors, locks,
Deadlock zDeadlock is a problem that can exist when a group of processes compete for access to fixed resources. zDefinition: deadlock exists among a set.
CS6502 Operating Systems - Dr. J. Garrido Deadlock – Part 2 (Lecture 7a) CS5002 Operating Systems Dr. Jose M. Garrido.
This Time - Deadlock Definition Conditions for deadlocks
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.
Styresystemer og Multiprogrammering Block 3, 2005 Deadlocks Robert Glück.
Silberschatz, Galvin and Gagne ©2009 Edited by Khoury, 2015 Operating System Concepts – 9 th Edition, Chapter 7: Deadlocks.
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. 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.
Chapter 7: Deadlocks.
OPERATING SYSTEM CONCEPTS AND PRACTISE
Process Management Deadlocks.
Synchronization Deadlocks and prevention
Chapter 7: Deadlocks.
Concurrency: Deadlock and Starvation
Deadlock Management.
ITEC 202 Operating Systems
G.Anuradha Ref:- Galvin
Chapter 7: Deadlocks Source & Copyright: Operating System Concepts, Silberschatz, Galvin and Gagne.
Operating Systems (CS 340 D)
Chapter 7: Deadlocks.
Advanced Operating System Fall 2009
Operating System: DEADLOCKS
Chapter 7 Deadlocks.
Chapter 7: Deadlocks.
Process Deadlocks.
Chapter 7: Deadlocks.
Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks
Deadlock B.Ramamurthy CSE421 1/11/2019 B.Ramamurthy.
Lecture 6: Deadlocks, Deadlock Risk Management
G.Anuradha Ref:- Galvin
Chapter 7: Deadlocks.
CSc 552 Advanced Unix Process deadlock deadlock prevention
DPNM Lab. Dept. of CSE, POSTECH
Chapter 8: Deadlocks.
Deadlock B.Ramamurthy CSE421 2/23/2019 B.Ramamurthy.
Deadlocks Session - 13.
DEADLOCK.
Chapter 7: Deadlocks.
Deadlock Hank Levy 1.
Deadlock B.Ramamurthy CSE421 4/23/2019 B.Ramamurthy.
CSE 153 Design of Operating Systems Winter 2019
Deadlock B.Ramamurthy CSE421 5/1/2019 B.Ramamurthy.
OPERATING SYSTEMS DEADLOCKS.
Chapter 7: Deadlocks.
Chapter 7: Deadlocks.
Deadlock B.Ramamurthy CSE421 8/28/2019 B.Ramamurthy.
Deadlock B.Ramamurthy CSE421 9/3/2019 B.Ramamurthy.
Presentation transcript:

CSE 120 Principles of Operating Systems Spring 2016 Deadlock

Deadlock Synchronization is a live gun – we can easily shoot ourselves in the foot Incorrect use of synchronization can block all processes You have likely been intuitively avoiding this situation already More generally, processes that allocate multiple resources generate dependencies on those resources Locks, semaphores, monitors, etc., just represent the resources that they protect If one process tries to allocate a resource that a second process holds, and vice-versa, they can never make progress We call this situation deadlock, and we’ll look at: Definition and conditions necessary for deadlock Representation of deadlock conditions Approaches to dealing with deadlock October 20, 2015 CSE 120 – Lecture 8 – Scheduling and Deadlock

Deadlock Definition Deadlock is a problem that can arise: Definition: When processes compete for access to limited resources When processes are incorrectly synchronized Definition: Deadlock exists among a set of processes if every process is waiting for an event that can be caused only by another process in the set. Process 1 Process 2 lockA->Acquire(); … lockB->Acquire(); lockB->Acquire(); … lockA->Acquire(); October 20, 2015 CSE 120 – Lecture 8 – Scheduling and Deadlock

Conditions for Deadlock Deadlock can exist if and only if the following four conditions hold simultaneously: Mutual exclusion – At least one resource must be held in a non-sharable mode Hold and wait – There must be one process holding one resource and waiting for another resource No preemption – Resources cannot be preempted (critical sections cannot be aborted externally) Circular wait – There must exist a set of processes [P1, P2, P3,…,Pn] such that P1 is waiting for P2, P2 for P3, etc. October 20, 2015 CSE 120 – Lecture 8 – Scheduling and Deadlock

Resource Allocation Graph Deadlock can be described using a resource allocation graph (RAG) The RAG consists of a set of vertices P={P1, P2, …, Pn} of processes and R={R1, R2, …, Rm} of resources A directed edge from a process to a resource, PiRi, means that Pi has requested Rj A directed edge from a resource to a process, RiPi, means that Rj has been allocated by Pi Each resource has a fixed number of units If the graph has no cycles, deadlock cannot exist If the graph has a cycle, deadlock may exist October 20, 2015 CSE 120 – Lecture 8 – Scheduling and Deadlock

RAG Example A cycle…and deadlock! Same cycle…but no deadlock. Why? October 20, 2015 CSE 120 – Lecture 8 – Scheduling and Deadlock

A Simpler Case If all resources are single unit and all processes make single requests, then we can represent the resource state with a simpler waits-for graph (WFG) The WFG consists of a set of vertices P={P1, P2, …, Pn} of processes A directed edge PiPj means that Pi has requested a resource that Pj currently holds If the graph has no cycles, deadlock cannot exist If the graph has a cycle, deadlock exists October 20, 2015 CSE 120 – Lecture 8 – Scheduling and Deadlock

Dealing With Deadlock There are four approaches for dealing with deadlock: Ignore it – how lucky do you feel? Prevention – make it impossible for deadlock to happen Avoidance – control allocation of resources Detection and Recovery – look for a cycle in dependencies October 20, 2015 CSE 120 – Lecture 8 – Scheduling and Deadlock

Deadlock Prevention Prevention – Ensure that at least one of the necessary conditions cannot happen Mutual exclusion » Make resources sharable (not generally practical) Hold and wait » Process cannot hold one resource when requesting another » Process requests, releases all needed resources at once Preemption » OS can preempt resource (costly) Circular wait » Impose an ordering (numbering) on the resources and request them in order (popular implementation technique) October 20, 2015 CSE 120 – Lecture 8 – Scheduling and Deadlock

Deadlock Avoidance Avoidance Tough Provide information in advance about what resources will be needed by processes to guarantee that deadlock will not happen System only grants resource requests if it knows that the process can obtain all resources it needs in future requests Avoids circularities (wait dependencies) Tough Hard to determine all resources needed in advance Good theoretical problem, not as practical to use October 20, 2015 CSE 120 – Lecture 8 – Scheduling and Deadlock

Banker’s Algorithm The Banker’s Algorithm is the classic approach to deadlock avoidance for resources with multiple units Assign a credit limit to each customer (process) Maximum credit claim must be stated in advance Reject any request that leads to a dangerous state A dangerous state is one where a sudden request by any customer for the full credit limit could lead to deadlock A recursive reduction procedure recognizes dangerous states In practice, the system must keep resource usage well below capacity to maintain a resource surplus Rarely used in practice due to low resource utilization October 20, 2015 CSE 120 – Lecture 8 – Scheduling and Deadlock

Banker’s Algorithm Simplified OK OK OK UNSAFE 3 3 3 3 3 3 3 3 October 28, 2014 CSE 120 – Lecture 8 – Scheduling and Deadlock 12

Detection and Recovery If we don’t have deadlock prevention or avoidance, then deadlock may occur In this case, we need to detect deadlock and recover from it To do this, we need two algorithms One to determine whether a deadlock has occurred Another to recover from the deadlock Possible, but expensive (time consuming) Implemented in VMS Run detection algorithm when resource request times out October 20, 2015 CSE 120 – Lecture 8 – Scheduling and Deadlock 13

Deadlock Detection Detection Expensive Traverse the resource graph looking for cycles If a cycle is found, preempt resource (force a process to release) Expensive Many processes and resources to traverse Only invoke detection algorithm depending on How often or likely deadlock is How many processes are likely to be affected when it occurs October 20, 2015 CSE 120 – Lecture 8 – Scheduling and Deadlock 14

Deadlock Recovery Once a deadlock is detected, we have two options… Abort processes Abort all deadlocked processes » Processes need to start over again Abort one process at a time until cycle is eliminated » System needs to rerun detection after each abort Preempt resources (force their release) Need to select process and resource to preempt Need to rollback process to previous state Need to prevent starvation October 20, 2015 CSE 120 – Lecture 8 – Scheduling and Deadlock 15

Deadlock Summary Deadlock occurs when processes are waiting on each other and cannot make progress Cycles in Resource Allocation Graph (RAG) Deadlock requires four conditions Mutual exclusion, hold and wait, no resource preemption, circular wait Four approaches to dealing with deadlock: Ignore it – Living life on the edge Prevention – Make one of the four conditions impossible Avoidance – Banker’s Algorithm (control allocation) Detection and Recovery – Look for a cycle, preempt or abort October 20, 2015 CSE 120 – Lecture 8 – Scheduling and Deadlock 16

Deadlock and Resources There are two kinds of resources: consumable and reusable Consumable resources are generated and destroyed by processes: e.g., a process waiting for a message from another process Reusable resources are allocated and released by processes: e.g., locks on files Deadlock with consumable resources is usually treated as a correctness issue (e.g., proofs) or with timeouts From here on, we only consider reusable resources October 28, 2014 CSE 120 – Lecture 8 – Scheduling and Deadlock 17

Deadlock Prevention Consider a database system in which a user submits commands that read and update tables. Tables that are read or updated need to be locked when accessed. How would you do each of the following? Don't enforce mutex? Don't allow hold and wait? Allow preemption? Don't allow circular waiting? October 28, 2014 CSE 120 – Lecture 8 – Scheduling and Deadlock 18