Download presentation
Presentation is loading. Please wait.
1
Chapter 7: Deadlocks
2
Chapter 7: Deadlocks The Deadlock Problem System Model
Deadlock Characterization Methods for Handling Deadlocks
3
Chapter Objectives To develop a description of deadlocks, which prevent sets of concurrent processes from completing their tasks To present methods for Handling Deadlocks
4
Introduction
5
Introduction In a multiprogramming environment, several processes may compete for a finite number of resources. A process requests resources; if the resources are not available at that time, the process enters a waiting state. Sometimes, a waiting process is never again able to change state, because the resources it has requested are held by other waiting processes. This situation is called a DEADLOCK.
6
The Deadlock Problem What is a deadlock problem??
A set of blocked processes each holding a resource and waiting to acquire a resource held by another process in the set Example System has 2 disk drives P1 and P2 each hold one disk drive and each needs another one Note :– Most OSs do not prevent or deal with deadlocks
7
Bridge Crossing Example
Traffic only in one direction Each section of a bridge can be viewed as a resource If a deadlock occurs, it can be resolved if one car backs up (preempt resources and rollback) Several cars may have to be backed up if a deadlock occurs Starvation is possible
8
System Model
9
System Model The resources are partitioned into several types (R1, R2, . . ., Rm ) E.g.: CPU cycles, memory space, I/O devices Each resource type Ri has Wi instances. Examples: If a system has (2) CPUs, then the resource type CPU has (2) instances. The resource type printer may have (5) instances. Each process utilizes a resource as follows: Request >> If the request cannot be granted immediately ,then the requesting process must wait until it can acquire the resource. Use Release Instances are identical
10
System Model (cont.) A set of processes is in a deadlocked state when every process in the set is waiting for an event that can be caused only by another process in the set. Resource forms: Physical resources e.g. printers, DVD drives, memory space, and CPU cycles Logical resources e.g. files Example: consider a system with one printer and one DVD drive. Suppose that process Pi is holding the DVD and process Pj is holding the printer. If Pi requests the printer and Pj requests the DVD drive, a deadlock occurs.
11
Deadlock Characterization
12
Deadlock Characterization
Deadlock can arise if four conditions hold simultaneously: Mutual exclusion: only one process at a time can use a resource…(i.e. No recourse sharing) Hold and wait: a process holding at least one resource is waiting to acquire additional resources held by other processes No preemption: a resource can be released only voluntarily by the process holding it, after that process has completed its task Circular wait: There exists a set {P0, P1, …, Pn} 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, Pn is waiting for a resource that is held by P0.
13
Resource-Allocation Graph
Deadlocks can be described in terms of a directed graph called a system resource-allocation graph. This graph consists of a set of vertices V and a set of edges E. V is partitioned into two types: P = {P1, P2, …, Pn}, the set consisting of all the processes in the system R = {R1, R2, …, Rm}, the set consisting of all resource types in the system E is partitioned into two types: Request edge – directed edge Pi Rj Assignment edge – directed edge Rj Pi
14
Resource-Allocation Graph (Cont.)
Process Resource Type with 4 instances Pi requests instance of Rj Pi is holding an instance of Rj Pi Rj Pi Rj
15
Example of a Resource Allocation Graph
The sets P, R, and E: P = {P1, P2, P3} R = {R1, R2, R3, R4} E = {P1 → R1, P2 → R3, R1 → P2, R2 → P2, R2 → P1, R3 → P3} Resource instances: (1) instance of resource type R1 (2) instances of resource type R2 (1) instance of resource type R3 (3) instances of resource type R4 Process states: Process P1 is holding an instance of resource type R2 and is waiting for an instance of resource type R1. Process P2 is holding an instance of R1 and an instance of R2 and is waiting for an instance of R3. Process P3 is holding an instance of R3.
16
Basic Facts How we recognize deadlock by using a Resource Allocation Graph?? If graph contains no cycles no deadlock If graph contains a cycle If only one instance per resource type, then there is a deadlock If several instances per resource type, possibility of deadlock .
17
Resource Allocation Graph With NO Deadlock
Example (1): The graph contains NO cycles NO deadlock is occurred.
18
Resource Allocation Graph With a Deadlock
Example (2): The graph contains (2)cycles may be a deadlock is occurred. Cycle (1) : P1 → R1 → P2 → R3 → P3 → R2 → P1 Cycle (2) :P2 → R3 → P3 → R2 → P2 It ‘s a dead lock situation >>> Processes P1, P2, and P3 are deadlocked…….why?? There is no chance to break the cycle.
19
Graph With A Cycle But No Deadlock
Example (3): The graph contains (1)cycle may be a deadlock Cycle : P1 → R1 → P3 → R2 → P1 NO dead lock situation .....WHY???? process P4 may release its instance of resource type R2…… That resource can then be allocated to P3, breaking the cycle.
20
Methods for Handling Deadlocks
21
Methods for Handling Deadlocks
OS can deal with the deadlock problem in one of three ways: Use a protocol to prevent or avoid deadlocks, ensuring that the system will never enter a deadlocked state. Allow the system to enter a deadlocked state, detect it, and recover. Ignore the problem altogether and pretend that deadlocks never occur in the system. Used by most operating systems, including Unix & windows This method is cheaper than the prevention, avoidance, or detection and recovery methods. Solution: The system must be restarted manually.
22
End of Chapter 7
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.