0% found this document useful (0 votes)
4 views16 pages

Deadlocks

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views16 pages

Deadlocks

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Deadlock

• A process requests resources for its execution,


• if the resources are not available at that time,
the process enters a waiting state.
• Sometimes, the resources it has requested are
held by other waiting processes, hence the
current process never changes its (waiting)
state.
• This situation is called a Deadlock.
Resources - System Model

• A system consists of a finite number of resources, to be distributed among


several competing processes.
• The resources may be partitioned into several types, each consisting of some
number of identical instances.
• CPU cycles, files, and I/O devices (such as printers and DVD drives) are
examples of resource types.
Resources - System Model

• If a system has two CPUs, then the resource type CPU has two instances.
• Similarly, the resource type printer may have five instances.
• If a process requests an instance of a resource type, the allocation of any
instance of the type should satisfy the request.
• If it does not, then the instances are not identical, and the resource type
classes have not been defined properly.
System Model - Sequence of Resource Utilization

• Under the normal mode of operation, a process utilize a resource in only the
following sequence:
• 1. Request.
• The process requests the resource.
• If the request cannot be granted immediately then the requesting
process must wait until it can acquire the resource.
• 2. Use.
• The process can operate on the resource.
• 3. Release.
• The process releases the resource.
Necessary Conditions

• A deadlock situation can arise, if the following four conditions hold


simultaneously in a system

• 1. Mutual exclusion.
• 2. Hold and wait.
• 3. No preemption.
• 4. Circular wait.
1. Mutual exclusion

• At least one resource must be held in a non sharable mode;


• that is, only one process at a time can use the resource.
• If another process requests that resource, the requesting process must wait
until the resource has been released.
2. Hold and wait

• A process must be holding at least one resource and


• waiting to acquire additional resources
• that are currently being held by other processes.
3. No preemption.

• Resources cannot be preempted;


• that is, a resource can be released only voluntarily by the process holding it,
• after that process has completed its task.
4. Circular wait.

• A set {P0, P1, ..., Pn] of waiting processes must exist


• such that P0 is waiting for a resource held by P1,
• P1 is waiting for a resource held by P2,...,
• Pn-1 is waiting for a resource held by Pn, and
• Pn is waiting for a resource held by P0.
Resource-Allocation Graph (RAG)

• A graph G consists of a set of vertices V and a set of edges E


• G={V,E)
• In Resource-Allocation Graph - RAG,
• 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
• Two types of directed edge
• Request edge - directed edge Pi -> Rj
• Assignment edge - directed edge Rj -> Pi
Resource-Allocation Graph (RAG)
Resource-Allocation Graph (RAG)

• 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:
• One instance of resource type R1
• Two instances of resource type R2
• One instance of resource type R3
• Three 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.
Resource-Allocation Graph (RAG)

• If the graph contains no cycles, then no process in the system is


deadlocked.
• In this graph, there is no cycle.
• The execution sequence of P1, P2 and P3 are
• 1. P3 executes first, then it releases the R3
• 2. R3 then assigned to P2, hence P2 completes its execution
• Then it releases the resources R1, R2 and R3
• 3. Now R1 assigned to P1, and P1 completes its execution.
Graph With A Cycle But No Deadlock

• The execution sequence of P2,P1, P4 and P3


Basic Facts identified from Resource Allocation Graph

• If graph contains no cycles =› no deadlock


• If graph contains a cycle =›
• if only one instance per resource type, then deadlock
• if several instances per resource type, possibility of deadlock

You might also like