Vous êtes sur la page 1sur 15

DEADLOCKS

System model
In multiprogramming environment , several processes compete for a finite no. of resources. If a process request an unavailable resource , process enters wait state. Waiting process never change state because the requesting resource is held by other waiting process. This situation is called deadlock.

A system consist of several resources resources are partitioned into several types each of which consist of identical instances
Resource types R1, R2, . . ., Rm CPU cycles, memory space, I/O devices Each resource type Ri has Wi instances.

If a process requests an instance of a resource type , allocation of any instance of the type will satisfy the request.
Each process utilizes a resource as follows: request - if not granted process must wait use release

A process may request as many resources as it requires to accomplish the task No. of resources requested must not exceed total no. of resources available. Request and release are system calls - Request and release device - open and close file - allocate and free memory - wait and signal operation on semaphore

A system table - record whether a resource is free or allocated - if allocated, to which process Definition : A set of processes is deadlocked if each process in the set is waiting for an event(resource acquisition and release) that can be caused only by another process in the set.

Consider system with 2 tape drives


process 1 requests tape drive 1 & gets it process 2 requests tape drive 2 & gets it process 1 requests tape drive 2 but is blocked process 2 requests tape drive 1 but is blocked Processes are in deadlock state Each is waiting for an event tape drive release which can be caused only by one of the other waiting processes.

DEADLOCK CHARACTERISATION
NECESSARY CONDITIONS ALL of these four must happen simultaneously for a deadlock to occur:

Mutual exclusion At least one resource must be in a non-sharable (exclusive) mode. Ie., only one process at a time can use a resource. Hold and Wait a process holding at least one resource and is waiting to acquire additional resources that are currently 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, , P0} 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, , Pn1 is waiting for a resource that is held by Pn, and Pn is waiting for a resource that is held by P0.

Resource-Allocation Graph
A deadlock can be described by 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.

request edge directed edge Pi Rj assignment edge directed edge Rj Pi


Process

Rj

Resource Type with 4 instances


Pi
Rj

Pi requests instance of Rj
Pi
Rj

Pi is holding an instance of Rj

Example of a Resource Allocation Graph

Resource Allocation Graph With A Deadlock

If graph contains no cycle then no process in the system is deadlocked. If graph contains a cycle then deadlock may exist If each resource type has exactly one instance then a cycle implies a deadlock has occurred. In this case cycle in the graph is a necessary and sufficient condition for existence of deadlock If each resource type has several instances then a cycle does not necessarily imply a deadlock has occurred. In this case cycle in the graph is not a necessary and sufficient condition for existence of deadlock

Two cycles P2 -> R3 -> P3 -> R2 -> P2 P1 -> R1 -> P2 -> R3 -> P3 -> R2 -> P1 P1,P2,P3 are deadlocked

Graph With A Cycle But No Deadlock

P4 may release R2. that can be allocated to P3 breaking the cycle.

Vous aimerez peut-être aussi