Deadlocks (part II) Deadlock avoidance – (not reasonable)

Slides:



Advertisements
Similar presentations
Operating Systems Lecture Notes Deadlocks Matthew Dailey Some material © Silberschatz, Galvin, and Gagne, 2002.
Advertisements

1 Deadlock Solutions: Avoidance, Detection, and Recovery CS 241 March 30, 2012 University of Illinois.
6. Deadlocks 6.1 Deadlocks with Reusable and Consumable Resources
Ceng Operating Systems Chapter 2.4 : Deadlocks Process concept  Process scheduling  Interprocess communication  Deadlocks Threads.
1 CSC 539: Operating Systems Structure and Design Spring 2005 Process deadlock  deadlock prevention  deadlock avoidance  deadlock detection  recovery.
Chapter 3 Deadlocks TOPICS Resource Deadlocks The ostrich algorithm
1 Deadlocks Chapter Resource 3.2. Introduction to deadlocks 3.3. The ostrich algorithm 3.4. Deadlock detection and recovery 3.5. Deadlock avoidance.
1 CSE 380 Computer Operating Systems Instructor: Insup Lee and Dianna Xu University of Pennsylvania, Fall 2003 Lecture Note: Deadlocks.
Avishai Wool lecture Introduction to Systems Programming Lecture 5 Deadlocks.
Deadlock Chapter 3 R1 R2 P2P1 Allocated Requested.
1 Wednesday, June 28, 2006 Command, n.: Statement presented by a human and accepted by a computer in such a manner as to make the human feel that he is.
Deadlocks. 2 System Model There are non-shared computer resources –Maybe more than one instance –Printers, Semaphores, Tape drives, CPU Processes need.
The ‘deadlock’ conditions Reviewing some key points concerning the potential for ‘deadlock’ in an operating system.
Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks
Chapter 6 Concurrency: Deadlock and Starvation
Silberschatz, Galvin and Gagne  Operating System Concepts Deadlock and Starvation Deadlock – two or more processes are waiting indefinitely for.
Deadlock Chapter 3 Thursday, February 22, Today’s Schedule Assignment #4 from Chapter 3 posted Deadlock - Chapter 3  Skip multiple resources (3.4.2.
1 Deadlocks Chapter Resource 3.2. Introduction to deadlocks 3.3. The ostrich algorithm 3.4. Deadlock detection and recovery 3.5. Deadlock avoidance.
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 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.
1 Deadlocks Chapter 3. 2 Resources Examples of computer resources –printers –tape drives –tables Processes need access to resources in reasonable order.
Operating Systems 软件学院 高海昌 Operating Systems Gao Haichang, Software School, Xidian University 22 Contents  1. Introduction** 
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 (OS)
1 MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 6 Deadlocks Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc.
1 Deadlock. 2 Concurrency Issues Past lectures:  Problem: Safely coordinate access to shared resource  Solutions:  Use semaphores, monitors, locks,
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
Operating Systems (CS 340 D) Dr. Abeer Mahmoud Princess Nora University Faculty of Computer & Information Systems Computer science Department.
CS 346 – Chapter 7 Deadlock –Properties –Analysis: directed graph Handle –Prevent –Avoid Safe states and the Banker’s algorithm –Detect –Recover.
Deadlocks System Model RAG Deadlock Characterization
Resource Management: Chap 9 Reusable  Disk blocks  File descriptors  Semaphores Consumable  Messages  Packets.
Deadlocks.  Deadlocks: Occurs when threads are waiting for resources with circular dependencies Often involve nonpreemptable resources, which cannot.
Deadlock A deadlock is a situation wherein two or more competing actions are waiting for the other to finish, and thus neither ever does. Example : “When.
Copyright ©: Nahrstedt, Angrave, Abdelzaher1 Deadlock.
Deadlocks References –text: Tanenbaum ch.3. Deadly Embrace Deadlock definition –A set of process is dead locked if each process in the set is waiting.
ICS Deadlocks 6.1 Deadlocks with Reusable and Consumable Resources 6.2 Approaches to the Deadlock Problem 6.3 A System Model –Resource Graphs –State.
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);
Sistem Operasi IKH311 Deadlock. 2 Resources Examples of computer resources printers tape drives tables Processes need access to resources in reasonable.
Process Management Deadlocks.
CSE 120 Principles of Operating
Concurrency: Deadlock and Starvation
ITEC 202 Operating Systems
G.Anuradha Ref:- Galvin
Chapter 6 : Deadlocks What is a Deadlock?
Deadlocks (part II) Deadlock avoidance – (not reasonable)
Operating Systems (CS 340 D)
ICS 143 Principles of Operating Systems
Operating Systems: Deadlock
Lecture 19: Deadlock: Conditions, Detection and Avoidance
Deadlock avoidance Deadlock detection Resource Allocation Graphs
COMS Prelim 1 Review Session
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.
CSc 552 Advanced Unix Process deadlock deadlock prevention
DPNM Lab. Dept. of CSE, POSTECH
Deadlocks Peng Lu In a multiprogramming environment, several processes may compete for a finite number of resources. A process requests resources; if the.
The relation between the process and
Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks
Deadlocks Session - 13.
Chapter 7: Deadlocks.
Lecture 19: Deadlock: Conditions, Detection and Avoidance
Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks
Deadlock © 2004, D. J. Foreman.
OPERATING SYSTEMS DEADLOCKS.
Introduction to Deadlocks
Deadlocks.
Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks
Deadlock CSE 2431: Introduction to Operating Systems
Presentation transcript:

Deadlocks (part II) Deadlock avoidance – (not reasonable) Deadlock detection Resource Allocation Graphs Resource Pool and Counting Semaphores

Resource Tables

Deadlock Definition A deadlock is a situation in which two or more competing actions are each waiting for the other to finish, and thus neither ever does. P1 P2 P(R1) P(R2) P(R2) P(R1) CS CS V(R2) V(R1) V(R1) V(R2)

Deadlock 4 necessary conditions Mutual Exclusion – Processes claim exclusive control of the resources they require Wait For – processes hold resources already allocated to them while waiting for additional resources No Pre-emption – resources cannot be removed from the process using them until it is used to completion Circular Wait – A circular chain of processes exist in which each process holds one or more resources that are requested by the next process in the chain.

Deadlock Avoidance (reasonable?) Designing an Operating System (Linux, Windows, iOS, Android etc.) that avoids deadlocks would require removing at least 1 of the 4 necessary conditions of deadlock. Many systems programmers would argue that the removal of any one of these 4 would limit the system too much and the gain of having a deadlock-free system would not be worth it. Just like driving a car, which can on (hopefully rare) occasions get a flat tire, it is popular to design systems that may on rare occasions go into deadlock and the system detects and deals with the problem at that time.

Deadlock Detection We need a way to detect that 2 or more processes are in a deadlock. Allow the system to run normally and occasionally have the Operating System check for deadlocks. If a deadlock is detected, the Operation System should attempt to fix the situation as best as it can which includes asking the users of a deadlocked process to volunteer it killing their process which will return resources to the system, which will then end the deadlock.

Asking the user to end Deadlock

Review of Data Structures and Algorithms Graphs can be recorded in memory Algorithms can be run on graphs that answer questions: What is the shortest path from point A to point B? Is a graph fully connected (yes or no)? Does a graph contain a cycle (yes or no)? If an existing graph which doesn’t currently have a cycle, was to have an edge added to it, would the graph now have a cycle?

Representing Graphs in Memory Adjacency matrix

Representing Graphs in Memory Adjacency lists

Deadlock (DAG with a cycle) A deadlock is a situation in which two or more competing actions are each waiting for the other to finish, and thus neither ever does. P1 P2 P(R1) P(R2) P(R2) P(R1) CS CS V(R2) V(R1) V(R1) V(R2)

Resource Pool A collection of identical resources Ex) A room full of printers Computer Storage (on the stack or heap)

Counting Semaphores When a system has multiple identical copies of a resource, a Counting Semaphore can be used to allow mutual access to that pool of identical resources. S=8 P(S) { if (S > 0) { S = S - 1; } else OS moves the process to the queue waiting for S Update resource tables and the Resource Allocation Graph

Counting Semaphores And the V function for counting semaphores is V(S) { if (a process is waiting for an S) OS moves the process to the ready queue } else S = S + 1; Update the resource tables and the RAG )

RAG – Resource Allocation Graph (with counting Semaphores)

Dijkstra’s Banker’s Algorithm – Safe State Total common resources is 8

Bankers Algorithm - 2 Resource Pools (not in a Safe State)

P(S) using Banker’s Algorithm { if (System would stay in a Safe State) { S = S - 1; } else OS moves the process to the queue waiting for S Update resource tables and the Resource Allocation Graph