Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 5

chapter sections 11.1-1.9 (definitions)2.8 , 22.1-2.7 33.1-3.4 44.1-4.4 55.1-5.3 66.1-6.6 77.1-7.4 88.1-8.5 99.1-9.

Deadlocks -7

1 .Contents of this chapter Deadlock: A process requests resources. Resource types R1, R2, . . ., R m (CPU cycles, memory space, I/O devices as printers ,scanners,etc)If the resources are not available , the process enters a wait state. Waiting processes may never change state, because the resources they have requested are held by other waiting . processes 2

Example of a deadlock: A system has 2 Processes P1 and P2 and (2 Resources ( 2 printers, or 1 printer and 1 scanner...etc P0,P1 And 2 semaphores A, B 3 Other example is two processes 3

Traffic only in one direction at the bridge. Starvation is possible: e.g. cars pass from left to right for a long time, cars on the right side starve. Deadlock could be solved by rollback and allows car .on opposite direction to pass 4

:System Model 7.1


The system contains Processes P1 , P2 , .., Pn Resource types R1, R2,

. . ., Rm CPU cycles, memory space, I/O devices. If a resource has many instances (e.g. 4 printers) then they must be allowed for all processes equally. 5 7.2 Deadlock Characterization: 4 conditions must be satisfied simultaneously for a deadlock to occur: 1 Mutual exclusion a resource is used only by one process (cannot be shared e.g. a printer cannot be shared) 2 Hold & wait: a process A must hold at least one resource and wait for other processes to release resources required by process A. 3 No preemption: A process releases a resource only voluntarily only after completing the task.

4 Circular wait: the processes in a deadlock set can be put in a set {P0, P1, , Pn} each process is waiting for a resource/resources held by the following process. 6&7 Resource-Allocation Graph: Vertices: circles: processes in the system P = {P1, P2, , Pn} Squares : resources in the system R = {R1, R2, , Rm} (may contain more than one instance (small squares inside) Edges: request edge directed edge arrow Pi Rj assignment edge directed edge arrow Rj Pi 8 Example of a Resource Allocation Graph There is no deadlock here (process P3 does not request any resource, does not wait and runs then releases R3 , R3 is allocated to P2, P2 runs then releases R1,R2,R3 then R1 is allocated to P1 that runs to end. 9 Resource Allocation Graph with A Deadlock: A Deadlock because P3 requests R2 (not available) and has to wait, P1 waits P2 to release R1 and P2 waits P3 to release R3 Resource R4 is not used by any process. The circular {wait set is set {P1, P2, P3 10

:Resource Allocation Graph With Cycle But No deadlock P4 is not waiting and runs then releases instance of R2 that will be assigned to P3 that runs and releases instance of R1, and P1 can run to end, i.e. the running processes will be P4 then P3 then P1. Also P2 can run without waiting to end, .then releases R1 and allows P1 to run to end 11 Basic facts If graph contains no cycles no deadlock. (e.g. no -1 circular wait as in slide 8 If graph contains a cycle -2 .if only one instance per resource type, then deadlock if several instances per resource type, possibility of (deadlock. Slide(10 :In slide 9 Two cycles R2 P2 R3 P3 R2 R2 P1 R1 P2 R3 P3 R2 -12 :Methods for Handling Deadlocks 7.3 a- Ensure that the system will never enter a deadlock state.( Deadlock prevention and (avoidance b-Allow the system to enter a deadlock state and then recover.( deadlock (recovery
.1

c-Ignore the problem and pretend that deadlocks never occur in the system; used by most operating systems, .including UNIX 14&13 :Deadlock Prevention 7.4 trying not to satisfy the 4 conditions of deadlock :mentioned in slide 5 as follows

.1

a-prevent mutual exclusion : some resources are sharable(read-only files) some not sharable(printers) and we (cannot change the properties to make it sharable(printers
b-Hold and Wait must guarantee that when a process requests a resource, it does not hold any other resources to prevent entering deadlock. If process to request and be allocated all its resources before it begins execution, then may exist starvation (unlimited wait for some (processes -:c-No preemption Allow preemption as follows If a process that is holding some resources requests another resource that cannot be immediately allocated to it, then all .resources currently being held are released d-Ordering all the resource types and require that each process requests resources in an increasing order of enumeration makes the circular wait

You might also like