Sie sind auf Seite 1von 59

DEADLOCKS

Group 3:
Gabriel Zialcita
Ralph Regan Choa
Elmer Soria
Marc Doroja
Nikko Reyes
Enrique Malonzo
Table of Contents

Introduction: What is DEADLOCKS

System Model

Conditions

Resource-Allocation Graph

Deadlock Prevention

Deadlock Avoidance

Deadlock Detection
What is Deadlocks?

•The event where several processes may compete for a finite number
of resources

•If the resources are not available at that time, the


process enters a wait state

•It may happen that waiting processes will never again change state,
because the resources they have requested are held by other waiting processes

This situation is called DEADLOCKS


Table of Contents

Introduction: What is DEADLOCKS

System Model

Conditions

Resource-Allocation Graph

Deadlock Prevention

Deadlock Avoidance

Deadlock Detection
System Model

resources to be distributed among competing processes.

rces: Memory space, CPU cycles, files

rce before using it, and must release the resource after using it.

est cannot be granted immediately, then the requesting process must wait until it

operate on the resource

releases the resource


System Model

resources

s requested and has been allocated the resource

is free or allocated, and, for each resource that is allocated, to which process

urce that is currently allocated to another process, it can be added to a queue o

tate when every process in the set is waiting for an event that can be caused by
System Model

rinters, tape drives, memory space, CPU cycles


les, semaphores, object locks, monitors

ing a tape drive, if each process now requests for a new tape drive , the 3 proces

ta type that provides a simple but useful abstraction for controlling access by multiple processes to a
Table of Contents

Introduction: What is DEADLOCKS

System Model

Conditions

Resource-Allocation Graph

Deadlock Prevention

Deadlock Avoidance

Deadlock Detection
Conditions

il it is done with the process.

for a resource that is held by P1, P1 is waiting for a resource that is held by P
Table of Contents

Introduction: What is DEADLOCKS

System Model

Conditions

Resource-Allocation Graph

Deadlock Prevention

Deadlock Avoidance

Deadlock Detection
Resource-Allocation Graph

Process

Resource Type with 4


instances

Pi Pi requests instance of Rj

Rj

Pi Pi is holding an instance of Rj

Rj
Resource-Allocation Graph
Resource-Allocation Graph
Resource-Allocation Graph
Resource-Allocation Graph
Resource-Allocation Graph
Resource-Allocation Graph
Resource-Allocation Graph
Resource-Allocation Graph
Resource-Allocation Graph
Resource-Allocation Graph
Resource-Allocation Graph
Resource-Allocation Graph
Table of Contents

Introduction: What is DEADLOCKS

System Model

Conditions

Resource-Allocation Graph

Deadlock Prevention

Deadlock Avoidance

Deadlock Detection
Deadlock Prevention

esources do not require mutually exclusive access at all, therefore precluding th

ces. This means an all-or-nothing style of requesting, requiring processes to reque


Deadlock Prevention

immediately, then all currently-held processes are preempted (i.e. removed). They a

numeration. The strict ordering will mean that no cycles will be present.
Table of Contents

Introduction: What is DEADLOCKS

System Model

Conditions

Resource-Allocation Graph

Deadlock Prevention

Deadlock Avoidance

Deadlock Detection
Deadlock Avoidance

iring the user/process to supply information regarding the req

of each type that it may need. Given this information, an alg


Deadlock Avoidance

is defined by the number of available and allocated resources

fter allocation and will grant the resources. Otherwise, it wi


Deadlock Avoidance

dditional a priori information available.

l model requires that each process declare the maximum number of resources of eac

algorithm dynamically examines the resource-allocation state to ensure that there

te is defined by the number of available and allocated resources, and the maximum
Safe State

e system in a safe state.


tems such that for each Pi, the resources that Pi can still r
Safe State

ds are not immediately available, then Pi can wait until all

d, Pi can obtain needed resources, execute, return allocated r

, Pi +1 can obtain its needed resources, and so on.


Basic Facts

a system is in safe state  no deadlocks.


a system is in unsafe state  possibility of deadlock.
idance  ensure that a system will never enter an unsafe sta
Safe, Unsafe, Deadlock State
Avoidance Algorithms

gle instance of a resource type. Use a resource-allocation gr

tiple instances of a resource type. Use the banker’s algorith


Resource-Allocation Graph Scheme

indicated that process Pj may request resource Rj; represente

s to request edge when a process requests a resource.


rted to an assignment edge when the resource is allocated to

released by a process, assignment edge reconverts to a claim


claimed a priori in the system.
Resource-Allocation Graph
Unsafe State In Resource-Allocation Graph
Resource-Allocation Graph Algorithm

request edge to an assignment edge does not result in the for


Question:

invalid), temporarily denied because of unavailability of r


Question:

•P1 requests for R1


•P2 requests for R3
•P3 requests for R2
•P4 requests for R4
•P5 requests for R4

•Say P3 requested for R4 and it was granted
•P5 requests for R3
•P4 requests for R4
•P3 requests for R2
•P3 requests for R3
•P2 requests for R3

Table of Contents

Introduction: What is DEADLOCKS

System Model

Conditions

Resource-Allocation Graph

Deadlock Prevention

Deadlock Avoidance

Deadlock Detection
Deadlock Detection

etection monitors the driver's use of resources which need to

lock detection attempts to find and resolve actual deadlocks


Wait for Graph Algorithm(WFG)

rches for a cycle in the graph. If there is a cycle, there exi

is holding a resource that Pi needs and thus Pi is waiting fo


ource-Allocation Graph to Wait-for Graph

a) Resource Allocation Graph b)


Wait-for Graph
Deadlock Detection(Multiple Instance)

STANCES OF A RESOURCE TYPE


is of order m * n * n.
keep track of:
able - records how many resources of each type are
ation - number of resources of type m allocated to
st - number of resources of type m requested by process
and finish be vectors of length m and n respectively.
Detection Algorithm

work [] = available []
= 1 , 2 ,... n , if allocation [ i ] != 0 then
finish [ i ] = false ; otherwise , finish [ i ] = true ;
such that :
== false and request [ i ] <= work
h i exists , go to step 4 .
work + allocation [ i ]
= true
ep 2
i] == false for some i , then the system is in deadlock
[i] == false , then process p [ i ] is deadlocked .
Example

instances, B has 2 instances, and C has 6 instances. At this


 Alloc   Req   Avail 
A B C A B C A B C
P0 0 1 0 0 0 0 0 0 0
P1 2 0 0 2 0 2
P2 3 0 3 0 0 0
P3 2 1 1 1 0 0
P4 0 0 2 0 0 2

•Sequence <P0, P2, P3, P1, P4> will result in Finish[i]


= true for all i.

Table of Contents

Deadlock Detection

Banker’s Algorithm

Deadlocks Recovery
Banker’s Algorithm

ocesses , and m = number of resources types

Vector of length m. If available [j] = k, there are k instances of resourc

rix. If Max [i,j] = k, then process Pi may request at most k instances of

n x mmatrix. If Allocation[i,j] = k then Pi is currently allocated k ins

matrix. If Need[i,j] = k, then Pi may need k more instances of Rj to comple

ax[i,j] – Allocation [i,j].


Safety Algorithm

rk and Finish be vectors of length m and n, respectively. I


ork = Available
inish [i] = false for i = 0, 1, …, n- 1.
n i such that both:
ish [i] = false
di  Work
uch i exists, go to step 4.
ork + Allocationi
] = true
tep 2.
nish [i] == true for all i, then the system is in a safe stat
Resource-Request Algorithm for Process Pi

process Pi. If Requesti [j] = k then process Pi wants k inst


to step 2. Otherwise, raise error condition, since process ha
le, go to step 3. Otherwise Pi must wait, since resources are
Resource-Request Algorithm for Process Pi

to allocate requested resources to Pi by modifying the state


• Available = Available – Request;
• Allocationi = Allocationi + Requesti;
• Needi = Needi – Requesti;

If safe  the resources are allocated to Pi.
If unsafe Pi must wait, and the old resource-allocation stat
Example of Banker’s Algorithm

•5 processes P0 through P4; 3 resource types:


A(10 instances), B (5instances), and C (7 instances).
•Snapshot at time T0:
Allocation Max Available
A B C A B C A B C
P0 0 1 0 7 5 3 3 3 2
P1 2 0 0 3 2 2
P2 3 0 2 9 0 2
P3 2 1 1 2 2 2
P4 0 0 2 4 3 3

Example (Cont.)

e matrix Need is defined to be Max – Allocation.

Need
A B C
P0 7 4 3
P1 1 2 2
P2 6 0 0
P3 0 1 1
P4 4 3 1

a safe state since the sequence < P1, P3, P4, P2, P0> satisfies
Example: P1 Request (1,0,2)

t  Available (that is, (1,0,2)  (3,3,2)  true.


Allocation Need Available
A B C A B CA B C
0 1 0 7 4 3 2 3 0
3 0 2 0 2 0
3 0 1 6 0 0
2 1 1 0 1 1
0 0 2 4 3 1
algorithm shows that sequence < P1, P3, P4, P0, P2> satisfies sa
,3,0) by P4 be granted?
,2,0) by P0 be granted?
Table of Contents

Deadlock Detection

Banker’s Algorithm

Deadlocks Recovery
Recovery from Deadlock: Process Termination

•Abort all deadlocked processes.

•Abort one process at a time until the deadlock cycle is eliminated.

•In which order should we choose to abort?


•Priority of the process.

•How long process has computed, and how much longer to completion

•Resources the process has used.

•Resources process needs to complete.

•How many processes will need to be terminated.

•Is process interactive or batch?
Recovery from Deadlock: Resource Preemption

– minimize cost.
o some safe state, restart process for that state.
process may always be picked as victim, include number of roll

Das könnte Ihnen auch gefallen