CIS 5512 - Operating Systems Deadlock Professor Qiang Zeng Fall 2015.

Slides:



Advertisements
Similar presentations
1 Concurrency: Deadlock and Starvation Chapter 6.
Advertisements

Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community.
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community.
1 Concurrency: Deadlock and Starvation Chapter 6.
Deadlock Prevention, Avoidance, and Detection
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.
Lecture 6 :Deadlocks. Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate with each other Involves.
Concurrency: Deadlock and Starvation Chapter 6. Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate.
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community.
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings Dave Bremer Otago Polytechnic,
Deadlock Prevention, Avoidance, and Detection.  The Deadlock problem The Deadlock problem  Conditions for deadlocks Conditions for deadlocks  Graph-theoretic.
Concurrency: Deadlock and Starvation Chapter 6. Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate.
Lecture 7: Deadlock     Necessary Conditions for Deadlock     Deadlock Prevention - Havender's Linear Ordering Deadlock Avoidance Deadlock Detection &
6. Deadlocks 6.1 Deadlocks with Reusable and Consumable Resources
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Chapter 6 Concurrency: Deadlock and Starvation
Chapter 6 Concurrency: Deadlock and Starvation
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.
Chapter 6 Concurrency: Deadlock and Starvation I
Concurrency : Deadlock and Starvation
Avishai Wool lecture Introduction to Systems Programming Lecture 5 Deadlocks.
Chapter 6 Concurrency: Deadlock and Starvation
Concurrency: Deadlock & Starvation
1 Lecture 8: Deadlocks Operating System Spring 2008.
OS Spring 2004 Concurrency: Principles of Deadlock Operating Systems Spring 2004.
Witawas Srisa-an Chapter 6
CPSC 4650 Operating Systems Chapter 6 Deadlock and Starvation
Chapter 7 – Deadlock and Indefinite Postponement
OS Fall’02 Concurrency: Principles of Deadlock Operating Systems Fall 2002.
1 Concurrency: Deadlock and Starvation Chapter 6.
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 Concurrency: Deadlock and Starvation Chapter 6.
Concurrency: Deadlock and Starvation
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings Dave Bremer Otago Polytechnic,
1 Deadlock Solutions CS 241 March 28, 2012 University of Illinois.
1 Announcements The fixing the bug part of Lab 4’s assignment 2 is now considered extra credit. Comments for the code should be on the parts you wrote.
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings Dave Bremer Otago Polytechnic,
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 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 System Chapter 6. Concurrency: Deadlock and Starvation Lynn Choi School of Electrical Engineering.
Deadlock Operating Systems: Internals and Design Principles.
Chapter 6 Concurrency: Deadlock and Starvation
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings.
Deadlocks Copyright ©: University of Illinois CS 241 Staff1.
Copyright ©: Nahrstedt, Angrave, Abdelzaher1 Deadlock.
Informationsteknologi Monday, October 1, 2007Computer Systems/Operating Systems - Class 111 Today’s class Deadlock.
DEADLOCKS Prepared By: Dr. Vipul Vekariya. D EADLOCK A set of processes is deadlocked when each process in the set is blocked awaiting an event that can.
Deadlock Operating Systems (CC2011NI) -Mr. Pranoy Man Pradhan.
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community.
Concurrency: Deadlock and Starvation
ITEC 202 Operating Systems
Chapter 7 – Deadlock and Indefinite Postponement
Chapter 12: Concurrency, Deadlock and Starvation
Deadlock B.Ramamurthy CSE421 9/17/2018 B.Ramamurthy.
Advanced Operating System Fall 2009
Chapter 7 Deadlock.
Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks
DEADLOCK.
Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks
Operating System 6 CONCURRENCY: MUTUAL EXCLUSION AND SYNCHRONIZATION
Deadlock B.Ramamurthy CSE421 4/26/2019 B.Ramamurthy.
Deadlock B.Ramamurthy CS421 5/4/2019 B.Ramamurthy.
Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks
Presentation transcript:

CIS Operating Systems Deadlock Professor Qiang Zeng Fall 2015

Previous class… Mutex Semaphore Concurrency problems CIS Operating Systems 2

Deadlock A set of processes is deadlocked when each process in the set is blocked awaiting an event that can only be triggered by another blocked process in the set CIS Operating Systems 3 Some Slides Courtesy of Dr. William Stallings

Potential Deadlock CIS Operating Systems 4 I need quad A and B I need quad B and C I need quad C and D I need quad D and A

Actual Deadlock CIS Operating Systems 5 HALT until B is free HALT until C is free HALT until D is free HALT until A is free

CIS Operating Systems 6 Reusable can be safely used by only one process at a time and is not depleted by that use processors, I/O channels, main and secondary memory, devices, and data structures such as files, databases, and semaphores Consumable one that can be created (produced) and destroyed (consumed) interrupts, signals, messages, and information in I/O buffers

Memory Request Space is available for allocation of 200Kbytes, and the following sequence of events occur: Deadlock occurs if both processes progress to their second request CIS Operating Systems 7 P1... Request 80 Kbytes ; Request 60 Kbytes; P2... Request 70 Kbytes ; Request 80 Kbytes;

Consider a pair of processes, in which each process attempts to receive a message from the other process and then send a message to the other process: Deadlock occurs if the Receive is blocking CIS Operating Systems 8

Resource Allocation Graphs CIS Operating Systems 9 There is a circle in the graph, which indicates deadlock

Resource Allocation Graph describing the traffic jam CIS Operating Systems 10

Conditions for Deadlock CIS Operating Systems 11 Mutual Exclusion A process cannot access a resource that has been allocated to another process Hold-and-Wait a process may hold allocated resources while awaiting assignment of others No Pre-emption no resource can be forcibly removed from a process holding it Circular Wait a closed chain of processes exists, such that each process holds at least one resource needed by the next process in the chain

Dealing with Deadlock Three general approaches exist for dealing with deadlock: CIS Operating Systems 12 adopt a policy that eliminates one of the conditions Prevent Deadlock make the appropriate dynamic choices based on the current state of resource allocation Avoid Deadlock attempt to detect the presence of deadlock and take action to recover Detect Deadlock

CIS Operating Systems 13 Mutual Exclusion if access to a resource requires mutual exclusion then it must be unlikely to share Hold and Wait require that a process request all of its required resources at one time and blocking the process until all requests can be granted simultaneously

Deadlock Condition Prevention No Preemption –if a process holding certain resources is denied a further request, that process must release its original resources and request them again Circular Wait –define a linear ordering of resource types – If a process has been allocated resources of type R, then it may subsequently request only those resources of types following R in the ordering. CIS Operating Systems 14

A decision is made dynamically whether the current resource allocation request will lead to an unsafe state Requires knowledge of future process requests CIS Operating Systems 15

CIS Operating Systems 16 State of a system consisting of 4 processes and 3 resources Allocations have been made as follows

P2 requests one 1 of R1 and 1 unit of R3 Should this request be granted? Banker’s algorithm: assume this request is granted, then check whether the resulted state is safe A state is safe if there is at least one sequence of resource allocations that satisfies all the processes’ needs CIS Operating Systems 17 Is this a safe state?

CIS Operating Systems 18 Available vector (0, 1, 1) + Allocated for P2 (6, 1, 2) = Updated available vector(6, 2, 3) Available vector (0, 1, 1) + Allocated for P2 (6, 1, 2) = Updated available vector(6, 2, 3)

CIS Operating Systems 19 Available vector (6, 2, 3) + Allocated for P1 (1, 0, 0) = Updated available vector(7, 2, 3) Available vector (6, 2, 3) + Allocated for P1 (1, 0, 0) = Updated available vector(7, 2, 3)

P3 Runs to Completion CIS Operating Systems 20 Thus, the state defined originally is safe

CIS Operating Systems 21 P1 requests for one more R1 and one more R3 The request should not be granted, because it leads to an unsafe state

Deadlock detection CIS Operating Systems 22

Recovery strategies –Kill all deadlocked processes –Kill one deadlocked process at a time and release its resources –Steal one resource at a time –Roll back all or one of the processes to a checkpoint that occurred before they requested any resources, then continue Difficult to prevent indefinite postponement CIS Operating Systems 23

Recovery by killing processes CIS Operating Systems 24

CIS Operating Systems 25

# define N 5 void philosopher (int i) { while (TRUE) { think(); take_fork(i); take_fork((i+1)%N); eat(); /* yummy */ put_fork(i); put_fork((i+1)%N); } Dining Philosophers solution with unnumbered resources

# define N 5 void philosopher (int i) { while (TRUE) { think(); take_fork(i); take_fork((i+1)%N); eat(); /* yummy */ put_fork(i); put_fork((i+1)%N); } Dining Philosophers solution with unnumbered resources

# define N 5 void philosopher (int i) { while (TRUE) { think(); take_fork(i); take_fork((i+1)%N); eat(); /* yummy */ put_fork(i); put_fork((i+1)%N); }

Dining Philosophers solution with numbered resources Instead, number resources First request lower numbered fork # define N 5 void philosopher (int i) { while (TRUE) { think(); take_fork(LOWER(i)); take_fork(HIGHER(i)); eat(); /* yummy */ put_fork(LOWER(i)); put_fork(HIGHER(i)); }

Dining Philosophers solution with numbered resources Instead, number resources... Then request higher numbered fork # define N 5 void philosopher (int i) { while (TRUE) { think(); take_fork(LOWER(i)); take_fork(HIGHER(i)); eat(); /* yummy */ put_fork(LOWER(i)); put_fork(HIGHER(i)); }

Dining Philosophers solution with numbered resources Instead, number resources... Then request higher numbered fork # define N 5 void philosopher (int i) { while (TRUE) { think(); take_fork(LOWER(i)); take_fork(HIGHER(i)); eat(); /* yummy */ put_fork(LOWER(i)); put_fork(HIGHER(i)); }

Dining Philosophers solution with numbered resources Instead, number resources... One philosopher can eat! # define N 5 void philosopher (int i) { while (TRUE) { think(); take_fork(LOWER(i)); take_fork(HIGHER(i)); eat(); /* yummy */ put_fork(LOWER(i)); put_fork(HIGHER(i)); }

Deadlock: Dealing with deadlock: –Prevention –Detection –Avoidance CIS Operating Systems 33