Concurrency: Deadlock and Starvation

Slides:



Advertisements
Similar presentations
Chapter 7: Deadlocks.
Advertisements

1 Concurrency: Deadlock and Starvation Chapter 6.
1 Concurrency: Deadlock and Starvation Chapter 6.
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.
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,
Concurrency: Deadlock and Starvation Chapter 6. Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate.
Chapter 7: Deadlocks.
Chapter 6 Concurrency: Deadlock and Starvation
Chapter 6 Concurrency: Deadlock and Starvation
Chapter 81 Deadlock is:  A set of blocked processes each holding a resource and waiting to acquire a resource held by another process in the set.  Example.
Chapter 6 Concurrency: Deadlock and Starvation I
Chapter 6 Concurrency: Deadlock and Starvation
Chapter 7. Deadlocks.
Chapter 7: Deadlocks. 7.2 Chapter Objectives To develop a description of deadlocks, which prevent sets of concurrent processes from completing their tasks.
1 Chapter 7: Deadlock. 2 The Deadlock Problem System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance.
Concurrency: Deadlock & Starvation
1 Lecture 8: Deadlocks Operating System Spring 2008.
1 M. Bozyigit ICS Operating Systems Deadlock. 2 Deadlock n Permanent blocking of a set of processes that either compete for system resources or communicate.
1 Concurrency: Deadlock and Starvation Chapter 6.
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
OS Fall’02 Concurrency: Principles of Deadlock Operating Systems Fall 2002.
1 Concurrency: Deadlock and Starvation Chapter 6.
Chapter 6 Concurrency: Deadlock and Starvation
What we will cover…  The Deadlock Problem  System Model  Deadlock Characterization  Methods for Handling Deadlocks  Deadlock Prevention  Deadlock.
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.
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings Dave Bremer Otago Polytechnic,
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,
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.
1 MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 6 Deadlocks Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc.
CHAPTER 8: DEADLOCKS System Model Deadlock Characterization
Operating System Chapter 6. Concurrency: Deadlock and Starvation Lynn Choi School of Electrical Engineering.
CS6502 Operating Systems - Dr. J. Garrido Deadlock – Part 2 (Lecture 7a) CS5002 Operating Systems Dr. Jose M. Garrido.
CIS Operating Systems Deadlock Professor Qiang Zeng Fall 2015.
Dr. Kalpakis CMSC 421, Operating Systems Deadlocks.
Deadlock Operating Systems: Internals and Design Principles.
Chapter 81 Deadlock Avoidance Technique  Resource Allocation Denial: Grant incremental resource requests if we can prove that this leaves the system in.
Chapter 6 Concurrency: Deadlock and Starvation
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings.
Chapter 8 Deadlocks. Objective System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance Deadlock Detection.
1 CS.217 Operating System By Ajarn..Sutapart Sappajak,METC,MSIT Chapter 6 Deadlocks Slide 1 Chapter 6 Deadlocks.
Informationsteknologi Monday, October 1, 2007Computer Systems/Operating Systems - Class 111 Today’s class 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);
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community.
Chapter 7: Deadlocks.
Concurrency: Deadlock and Starvation
ITEC 202 Operating Systems
Chapter 12: Concurrency, Deadlock and Starvation
Advanced Operating System Fall 2009
CHAPTER 6: Concurrency - Deadlock and Starvation
Chapter 7 Deadlock.
Chapter 7 Deadlocks.
G.Anuradha Ref:- Galvin
DEADLOCK.
Chapter 7: Deadlocks.
Operating System 6 CONCURRENCY: MUTUAL EXCLUSION AND SYNCHRONIZATION
Chapter 7: Deadlocks.
1 DEADLOCK AND STARVATION A Seminar Slide Presentation by CHUKWUEMEKA, UGONNA G. CHUKWUEMEKA, UGONNA G. Dr E.O Bennett (Course Lecturer) CSS Operating.
Presentation transcript:

Concurrency: Deadlock and Starvation Chapter 6

Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate with each other No efficient solution in general case Involve conflicting needs for resources by two or more processes

Resource Category There are two general categories of resources: Reusable Resources Consumable Resources

Reusable Resources Used by one process at a time and not depleted by that use Processes obtain resources that they later release for reuse by other processes E.g.- Processors, I/O channels, main and secondary memory, files, databases, and semaphores Deadlock occurs if each process holds one resource and requests the other

Example 1 Consider two processes that compete for exclusive access to disk file D and tape drive T. The program operations shown in figure 6.4 below.

Example 1 Deadlock occurs when the multiprogramming system interleaves the execution of two processes as follows: Deal with impose system design constraints concerning with the order which resources are requested. p0p1q0q1p2q2

Example 2 Space is available for allocation of 200K bytes, and the following sequence of events occur Deadlock occurs if both processes progress to their second request Deal with this problem is by using virtual memory. P1 . . . Request 80K bytes; Request 60K bytes; P2 Request 70K bytes;

Consumable Resources Created (produced) and destroyed (consumed) by a process May take a rare combination of events to cause deadlock E.g. - Interrupts, signals, messages, and information in I/O buffers

Example 1 Consider the following pair of processes, in which each process attempts to receive a message from the other process and then send a message to other process: Deadlock occurs if Receive() is blocking P1 . . . Receive(P2); Send(P2, M1); P2 Receive(P1); Send(P1, M2);

Conditions for Deadlock Four conditions of policy must be present for a deadlock to be possible: Mutual exclusion Hold and wait No preemption Circular wait

Conditions for Deadlock Mutual exclusion Only one process may use a resource at a time Hold-and-wait A process request all of its required resources at one time and will hold allocated resources while awaiting for other resources

Conditions for Deadlock 3. No preemption 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 once resources needed by the next process in the chain.

Conditions for Deadlock

Conditions for Deadlock Deadlock can and might not exist with the first three conditions The fourth condition is required. The fourth condition is actually a potential consequence of the first three.

Approaches for Deadlock The most important approaches that have been developed: Deadlock Prevention Prevent deadlock by adopting a policy that eliminates one of the conditions. Deadlock Avoidance Avoid deadlock by making the appropriate dynamic choices based on the current state of resource allocation. Deadlock Detection Attempt to detect the presence of deadlock and take action to recover.

Deadlock Prevention To design a system in such a way that the possibility of deadlock is excluded. Method falling into two classes: Indirect method to prevent the occurrence of one of the three necessary condition listed previously. Direct method to prevent the occurrence of circular wait.

Deadlock Prevention… Techniques related to each four: Mutual Exclusion (ME) Cannot be disallowed = MUST BE ALLOWED!! If access to resources require ME, then ME must be supported by the OS. But deadlock still can occur (in some resources): E.g.. Files may allow multiple accesses for reads but only exclusive for writes. Deadlock can occur if more than one process requires write permission.

Deadlock Prevention… Hold and Wait Prevented by requiring that a process request all of its required resources at one time and blocked the process until all request can be granted simultaneously. This approach inefficient because: Process may be held up for along time waiting for all of its resources to be filled, when in fact it could have been proceeded with only some of the resources. Resource allocated to a process may remain unused for a considerable period. During which time they are denied to other processes.

Deadlock Prevention… Process may not know in advance all of the resources that it will require. Also a practical problem created by the use of modular programming or multithreaded structure for an application need to be aware of all resources that will requested at all level or in all modules in order to make the simultaneous request.

Deadlock Prevention… 3. No Preemption Can be prevented in several ways: If a process holding certain resources is denied a further request, that process must release its original resources and if necessary request again with the additional resource. If a process request a resource that is currently held by another process, the OS must preempt the second process and require it to release its resource. Practical only when applied to resources whose state can be easily saved and restored later, e.g. a processor.

Deadlock Prevention… 4. Circular Wait Can be prevented by defining a linear ordering 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. E.g. Let us associate an index with a each resource type. Then resource Ra precedes Rc in the ordering if a< c (using alphabetical order).

Deadlock Prevention... Suppose that two processes, A and B, are deadlocked because A has acquired Ra and requested Rc, and B acquired Rc and requested Ra. This condition is impossible because it implies a < c and c < a circular wait prevention may be inefficient because it will slowing down process and denying resource access unnecessarily.

Deadlock Avoidance Allow the 3 policy conditions but make judicious choices to assure that the deadlock point is never reached Allows more concurrency than prevention A decision is made dynamically whether the current resource allocation request will, if granted, potentially lead to a deadlock Requires knowledge of future process request

Deadlock Avoidance… Two approaches to deadlock avoidance: Do not start a process if its demands might lead to deadlock Do not grant an incremental resource request to a process if this allocation might lead to deadlock In both cases: maximum requirements of each resource must be stated in advance

Deadlock Avoidance… Consider a system of n processes and m different types of resources. Definition of the vectors and matrices: Resource = R = (R1, R2,…, Rm) Total amount of each resource in the system Available = V = (V1, V2,…, Vm) Total amount of each resource not allocated to any process.

Deadlock Avoidance… Claim =C = C11, C12,…, C1m C21, C22,…, C2m Cn1, Cn2,…, Cnm Cij = requirement of process i for resource j Allocation = A = A11, A12,…, A1m A21, A22,…, A2m An1, An2,…, Anm Aij = current allocation to process i of resource j  matrix Claim gives the maximum requirement of each process. . . . . matrix Allocation shows current allocation for each process . . . .

Resource Allocation Denial Referred to as the banker’s algorithm State of the system is the current allocation of resources to process Safe state is where there is at least one sequence that does not result in deadlock Unsafe state ?

Example 1 Figure 6.7a shows the state of a system consisting of four processes and three resources. Total amount of resources R1, R2 and R3 are 9, 3 and 6 units. (Resource Vector) In the current state, allocations have been made to the four processes and leaving only 1 unit of R2 and 1 unit of R3 available (Available Vector). Is this a safe state?

Determination of a Safe State Initial State

Determination of a Safe State P2 Runs to Completion

Determination of a Safe State P1 Runs to Completion

Determination of a Safe State P3 Runs to Completion

Example 2 Figure 6.8a shows the state of a system consisting of four processes and three resources. Total amount of resources R1, R2 and R3 are 9, 3 and 6 units. (Resource Vector) In the current state, allocations have been made to the four processes and leaving only 1 unit of R1, 1 unit of R2 and 2 unit of R3 available (Available Vector). Suppose P1 make a request for 1 unit of R1 and 1 unit of R3. Is this a safe state?

Determination of an Unsafe State

Deadlock Avoidance… Advantage: But has a number of restrictions: Does not necessarily preempt and rollback processes compared to deadlock detection. But has a number of restrictions: Maximum resource requirement must be stated in advance Processes under consideration must be independent; no synchronization requirements There must be a fixed number of resources to allocate No process may exit while holding resources

Deadlock Detection Do not limit resource access or restrict process actions. Resource access are granted to process whenever possible. OS will periodically performs an algorithm to check if deadlock present an algorithm to recover from deadlock

Deadlock Detection… The deadlock check can be performed at every resource request. Checking at each resource request has two advantages: Leads to early detection Algorithm is simple because it is based on incremental changes to the state of the system. But such frequent checks will consume CPU time.

Deadlock Detection Algorithm The Allocation matrix and Available vector will be used. Request matrix Q is define such that Qij represent the amount of resources of type j requested by process i. The algorithm begins by marking processes that are not deadlock (Initially all processes are unmarked)

Deadlock Detection Then the following steps are performed: Mark each process that has a row in the Allocation matrix of all zeros. Initialize a temporary vector W to equal to Available vector. Find an index i such that process i is currently unmarked and ith row of Q <= W. If no such row found terminate the algorithm. If exist, mark process i and add the corresponding row of the Allocation matrix to W. Then return to step 3.

Deadlock Detection Deadlock exist if and only if there are unmarked processes at the end of algorithm Strategy in this algorithm is to find a process whose resource requests can be satisfied with the available resources and the assume that those resources are granted and the process runs to completion and release its resources. Then the algorithm will look for another process.

Deadlock Detection This algorithm will not guarantee to prevent deadlock, it will depend on the order in which requested are granted. It is only to determine either deadlock is currently exist or not.

Example

Example The algorithm proceeds as follows: Mark P4, because P4 has no allocated resources. Set W = ( 0 0 0 0 1 ) The request of P3 is less than equal to W, so mark P3 and set W = W + ( 0 0 0 1 0) = ( 0 0 0 1 1 ) No other unmarked process has a row in Q is less than or equal to W. Terminate the algorithm. The algorithm concludes with P1 and P2 unmarked. This processes are deadlocked.

Deadlock Detection Recovery Needed when deadlock is detected. The following approaches are possible: Abort all deadlocked processes (one of the most common solution adopted in OS) Back up each deadlocked process to some previously defined checkpoint, and restart all process.

Deadlock Detection Recovery Successively abort deadlock processes until deadlock no longer exists After each abortion, need to reinvoke the deadlock detection algorithm to see either deadlock still exists or not. Successively preempt some resources from processes and give them to other processes until deadlock no longer exists a process that has a resource preempted must be rolled back prior to its acquisition of that resource.

Deadlock Detection Recovery For approaches 3 and 4: a victim process needs to be selected according to: Least amount of processor time consumed so far Least number of lines of output produced so far Most estimated time remaining Least total resources allocated so far Lowest priority

Integrated Deadlock Strategy Combine the previous approaches into the following way: Group resources into a number of different resource classes Use the linear ordering strategy (prevention of circular wait) to prevent deadlock between resource classes Within a resource class, use the algorithm that is most appropriate for that class.

Integrated Deadlock Strategy Example of resource classes: Swappable space Blocks of memory on secondary storage for use in swapping processes. Process resources Assignable devices, such as tape drives and files Main memory Assignable to processes in pages and segments Internal resources Such as I/O channels