CSS430 Deadlocks Textbook Ch7

Slides:



Advertisements
Similar presentations
Chapter 7: Deadlocks.
Advertisements

Chapter 7: Deadlocks Adapted by Donghui Zhang from the original version by Silberschatz et al.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 7: Deadlocks.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 8: Deadlocks System Model Deadlock Characterization Methods for Handling Deadlocks.
Chapter 7: Deadlocks. 7.2 Chapter Objectives To develop a description of deadlocks, which prevent sets of concurrent processes from completing their tasks.
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 8: Deadlocks System Model Deadlock Characterization
02/19/2008CSCI 315 Operating Systems Design1 Deadlock Notice: The slides for this lecture have been largely based on those accompanying the textbook Operating.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 14, 2005 Chapter 7: Deadlocks The Deadlock.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 7: Deadlocks.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Bridge Crossing Example Traffic only in one direction. Each section.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Deadlocks.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 8: Deadlocks System Model Deadlock Characterization Methods for Handling Deadlocks.
Chapter 7: Deadlocks Adapted to COP4610 by Robert van Engelen.
System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention, Avoidance, and Detection Recovering from Deadlock Combined Approach.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 7: Deadlocks.
Chapter 7 Deadlocks. 7.2 Modified By Dr. Khaled Wassif Operating System Concepts – 7 th Edition Silberschatz, Galvin and Gagne ©2005 Chapter 7: Deadlocks.
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.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 AE4B33OSS Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock Characterization.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 7: Deadlocks.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock.
 The Deadlock Problem  System Model  Deadlock Characterization  Methods for Handling Deadlocks  Deadlock Prevention  Deadlock Avoidance  Deadlock.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 14, 2005 Chapter 7: Deadlocks The Deadlock.
Styresystemer og Multiprogrammering Block 3, 2005 Deadlocks Robert Glück.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 7: Deadlocks.
7.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock Characterization.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock.
1 CS.217 Operating System By Ajarn..Sutapart Sappajak,METC,MSIT Chapter 6 Deadlocks Slide 1 Chapter 6 Deadlocks.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock.
Deadlocks - System Model - Deadlock characterization - Methods for handling deadlocks - Deadlock prevention,avoidance - Deadlock detection and recovery.
Deadlock. Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock.
7.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 7: Deadlocks.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 14, 2005 Chapter 7: Deadlocks The 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);
Thursday, February 23, 2012 Chapter 6 homework questions?
Chapter 7: Deadlocks.
Synchronization Deadlocks and prevention
Chapter 7: Deadlocks.
G.Anuradha Ref:- Galvin
Chapter 7: Deadlocks Source & Copyright: Operating System Concepts, Silberschatz, Galvin and Gagne.
Operating Systems (CS 340 D)
Chapter 7: Deadlocks.
Operating System: DEADLOCKS
Chapter 7 Deadlocks.
Chapter 7: Deadlocks.
Process Deadlocks.
Chapter 7: Deadlocks.
Deadlock B.Ramamurthy CSE421 1/11/2019 B.Ramamurthy.
Lecture 6: Deadlocks, Deadlock Risk Management
G.Anuradha Ref:- Galvin
Chapter 7: Deadlocks.
Deadlock B.Ramamurthy CSE421 2/23/2019 B.Ramamurthy.
Deadlocks Session - 13.
Chapter 7: Deadlocks.
Deadlock B.Ramamurthy CSE421 4/23/2019 B.Ramamurthy.
CSS430 Deadlocks Textbook Ch8
Deadlock B.Ramamurthy CSE421 5/1/2019 B.Ramamurthy.
CSCI 315 Operating Systems Design
Chapter 7: Deadlocks.
Chapter 7: Deadlocks.
Chapter 7: Deadlock CSS503 Systems Programming
Chapter 8: Deadlocks Deadlock Characterization
OPERATING SYSTEM CONCEPTS
Deadlock B.Ramamurthy CSE421 8/28/2019 B.Ramamurthy.
Deadlock B.Ramamurthy CSE421 9/3/2019 B.Ramamurthy.
Presentation transcript:

CSS430 Deadlocks Textbook Ch7 These slides were compiled from the OSC textbook slides (Silberschatz, Galvin, and Gagne) and the instructor’s class materials. Hello! Everyone, My name is Shinya Kobayashi. Today, I am going to present our paper titled “Inter-Cluster Job Coordination Using Mobile Agents” on behalf of the first author, Munehiro Fukuda. Munehiro was hoping to show up and present the paper at AMS2001, however he got to wait in Japan until he will get an H1B visa. Since I received the presentation materials from him quite recently, please allow me to present this paper using this script. I can respond to your questions as far as I know, however you can also ask Munehiro by email. His email address is on the title page of our paper. (time 1:05) CSS430 Deadlocks

Deadlock Examples 1 Kansas Legislature: when two trains approach each other at a crossing, both shall come to a full stop and neither shall start up again until the other has gone. Two processes exchange a long message with each other, but their socket buffer is smaller than the message. Process A message message Process B Socket buffer Socket buffer CSS430 Deadlocks

Deadlock Examples 2 P0 P1 wait (A); wait(B) wait (B); wait(A) Bridge crossing example: traffic only in one direction where two cars are driving from the opposite direction. A deadlock is not resolved unless one gets back up. Two processes try to go into the same nested critical section in a different order. P0 P1 wait (A); wait(B) wait (B); wait(A) CSS430 Deadlocks

System Model Resource types R1, R2, . . ., Rm CPU cycles, memory space, I/O devices Each resource type Ri has Wi instances. Each process utilizes a resource as follows: request use release CSS430 Deadlocks

Deadlock Characterization Deadlock can arise if four conditions hold simultaneously. Mutual exclusion: only one process at a time can use a resource. Hold and wait: a process holding resource(s) is waiting to acquire additional resources held by other processes. No preemption: a resource can be released only voluntarily by the process holding it upon its task completion. Circular wait: there exists a set {P0, P1, …, P0} of waiting processes such that P0 is waiting for a resource that is held by P1, P1 is waiting for a resource that is held by P2, …, Pn–1 is waiting for a resource that is held by Pn, and Pn is waiting for a resource that is held by P0. CSS430 Deadlocks

Resource Allocation Graph Pi Rj Process Resource Type with 4 instances Pi requests instance of Rj Pi is holding an instance of Rj Pi releases an instance of Rj The sequence of Process’s recourse utilization Request edge Assignment edge CSS430 Deadlocks Rj

Resource-allocation graph Can a deadlock happen? CSS430 Deadlocks

Resource Allocation Graph With A Deadlock There are two cycles found. CSS430 Deadlocks

Resource Allocation Graph With A Cycle But No Deadlock If graph contains no cycles  no deadlock. If graph contains a cycle  if only one instance per resource type, then deadlock. if several instances per resource type, possibility of deadlock. CSS430 Deadlocks

Methods for Handling Deadlocks Ensure that the system will never enter a deadlock state. (Prevention and Avoidance) Allow the system to enter a deadlock state and then recover. (Detection and Recovery) Ignore the problem and pretend that deadlocks never occur in the system; used by most operating systems, including UNIX. CSS430 Deadlocks

Deadlock Prevention Restrain the following four conditions Mutual Exclusion – not required for sharable resources. (but not work always.) Hold and Wait – must guarantee that whenever a process requests a resource, it does not hold any other resources. Require a process to request and be allocated all its resources before its execution: Low resource utilization Allow process to request resources only when the process has none: starvation possible. No Preemption – If a process holding some resources requests another resource that cannot be immediately allocated to it, all resources currently being held are released. If a process P1 requests a resource R1 that is allocated to some other process P2 waiting for additional resource R2, R1 is allocated to P1. Circular Wait – impose a total ordering of all resource types, and require that each process requests resources in an increasing order of enumeration. CSS430 Deadlocks

Deadlock Prevention Circular Wait Not allowed Order(tape)=1 < Order(printer)=4 tape disk scanner printer 1 2 3 4 P1 P2 P3 CSS430 Deadlocks

Deadlock Avoidance Resource-Allocation Algorithm Let processes supply OS with future resource requests Cycle possibly formed (unsafe state), thus P2 has to wait for a safe state Claim edge (future request) Works out to only a single instance of each resource type. CSS430 Deadlocks

Deadlock Avoidance Banker’s Algorithm Multiple instances Each process must claim maximum use in advance. Requested resources are allocated only when there is a sequence all processes successfully obtain and release their resources. Proc Allocation Max Need Initial Available A B C A B C A B C A B C A B C P0 0 1 0 7 5 3 7 4 3 10 5 7 3 3 2 P1 2 0 0 3 2 2 1 2 2 P2 3 0 2 9 0 2 6 0 0 P3 2 1 1 2 2 2 0 1 1 P4 0 0 2 4 3 3 4 3 1 CSS430 Deadlocks

Deadlock Avoidance Banker’s Algorithm – P1 requested (1,0,2) Request (1,0,2) <= Available(3,3,2) is true Temporarily allocate it to P1 Work = Available = (2,3,0) Finish(f, f, f, f, f) if Finish[i] == false && Need[i] <= Work { Work += Allocation[i]; Finish[i] = true; } // allow Pi to obtain all its needs and to release them to available. Proc Allocation Max Need Initial Available A B C A B C A B C A B C A B C P0 0 1 0 7 5 3 7 4 3 10 5 7 3 3 2 P1 2 0 0 3 2 2 1 2 2 P2 3 0 2 9 0 2 6 0 0 P3 2 1 1 2 2 2 0 1 1 P4 0 0 2 4 3 3 4 3 1 3 0 2 2 3 0 0 2 0 added < added > added < added > added > Work: (2,3,0)->(5,3,2) -> (7,4,3) -> (7,4,5) -> (7,5,5) -> (10,5,7) CSS430 Deadlocks Thus, safe

Deadlock Detection and Recovery Cyclically construct resource-allocation graph and find a cycle in it. Recovery: Process termination Abort all deadlocked processes Abort processes one by one till a cycle is cut off. Successively preempt resources Selecting a victim Rolling back a resource use Ensuring avoiding starvation Should not select the same victim infinitely! CSS430 Deadlocks

Exercises (No turn-in) Why aren’t deadlock detection and recovery so attractive? Solve Exercise 7.3, 7.6, 7.9, 7.10, 7.14, and 7.19 Can the Java code in the next slide cause a deadlock? If so, write a resource allocation graph with a deadlock. CSS430 Deadlocks

CSS430 Deadlocks public class Deadlock { public Deadlock( ) { Mutex mutex[] = new Mutex[4]; for ( int i = 0; i < 4; i++ ) mutex[i] = new Mutex( ); A threadA = new A( mutex ); B threadB = new B( mutex ); C threadC = new C( mutex ); threadA.start( ); threadB.start( ); threadC.start( ); } public static void main( String arg[] ) { Deadlock d = new Deadlock( ); class Mutex{ } private class A extends Thread { private Mutex[] resource; public A( Mutex[] m ) { resource = m; public void run( ) { System.out.println( "A started" ); synchronized ( resource[1] ) { System.out.println( "A got rsc 1" ); synchronized ( resource[0] ) { System.out.println( "A got rsc 0" ); System.out.println( "A finished" ); private class B extends Thread { private Mutex[] resource; public B( Mutex[] m ) { resource = m; } public void run( ) { System.out.println( "B started" ); synchronized ( resource[3] ) { System.out.println( "B got rsc 3" ); synchronized ( resource[0] ) { System.out.println( "B got rsc 0" ); synchronized ( resource[2] ) { System.out.println( "B got rsc 2" ); System.out.println( "B finished" ); private class C extends Thread public C( Mutex[] m ) { System.out.println( "C started" ); System.out.println( "C got rsc 2" ); synchronized ( resource[1] ) { System.out.println( "C got rsc 1" ); System.out.println( "C finished" ); CSS430 Deadlocks