pros and cons of different strategies deadlock detection => graph reduction method –pros:...

8
Pros and Cons of different strategies Deadlock detection => graph reduction method Pros: maximum concurrency and resource utilization Cons: roll-back, cycle checking overhead even if not deadlocked Deadlock prevention => four necessary conditions Pros: suitable where roll-back is impossible or expensive Cons: inefficient due to preemption or low resource utilization Deadlock avoidance => banker’s algorithm Pros: no roll-back of processes required Cons: safe state checking overhead, safe state is overly conservative estimate, future resource requirements must be known a priori

Upload: suzan-rodgers

Post on 18-Dec-2015

228 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Pros and Cons of different strategies Deadlock detection => graph reduction method –Pros: maximum concurrency and resource utilization –Cons: roll-back,

Pros and Cons of different strategies• Deadlock detection => graph reduction method

– Pros: maximum concurrency and resource utilization– Cons: roll-back, cycle checking overhead even if not deadlocked

• Deadlock prevention => four necessary conditions– Pros: suitable where roll-back is impossible or expensive– Cons: inefficient due to preemption or low resource utilization

• Deadlock avoidance => banker’s algorithm– Pros: no roll-back of processes required– Cons: safe state checking overhead, safe state is overly conservative

estimate, future resource requirements must be known a priori

Page 2: Pros and Cons of different strategies Deadlock detection => graph reduction method –Pros: maximum concurrency and resource utilization –Cons: roll-back,

Deadlock avoidance• Avoidance can be seen as the middle ground approach to

deadlock handling – prevention strong guarantees: “no possibility of deadlock”

– detection no guarantees: “if deadlock happens we’ll deal with it”

– avoidance mild guarantee: “we’ll assign resource in a way that guarantees we will never get into a deadlock situation”

• The Banker’s algorithm is an example of resource allocation policy that avoids deadlock– Basic idea: think like a banker – grant a loan only if you have enough

reserves left to allow at least one of the other borrowers to complete his/her project and thus repay his/her loan

Page 3: Pros and Cons of different strategies Deadlock detection => graph reduction method –Pros: maximum concurrency and resource utilization –Cons: roll-back,

Banker’s algorithm

• Definitions for a system with n processors and m resources:

maaaA 21matrix Avail-Max

nnmnn

m

m

B

B

B

bbb

bbb

bbb

B

2

1

21

22221

11211

matrix Claim-Max

nnmnn

m

m

C

C

C

ccc

ccc

ccc

C

2

1

21

22221

11211

matrix AllocationCurrent

n

kkm CAdddD

121matrix AvailCurrent

nnmnn

m

m

E

E

E

CB

eee

eee

eee

E

2

1

21

22221

11211

matrix NeedCurrent

miiii fffF 21ctor Request ve

Page 4: Pros and Cons of different strategies Deadlock detection => graph reduction method –Pros: maximum concurrency and resource utilization –Cons: roll-back,

Algorithm steps• Step 1 - tentative accept of request

– D := D - F // update Current Avail matrix D– Ci := Ci + Fi // update Current Alloc vector Ci

– Ei := Ei - Fi // update Current Need matrix Ei

• Step 2 - safe-state checking test– see next slide in which

• freemoney = D• loan[i] = Ci

• need[i] = Ei

• Step 3 - if test positive definitive accept of request, otherwise roll back the updates of step 1

Page 5: Pros and Cons of different strategies Deadlock detection => graph reduction method –Pros: maximum concurrency and resource utilization –Cons: roll-back,

Banker at work: safe-state checkingWhile (last_iteration_successful) last_iteration_successful = false ; for i = 1 to N do if (finishdoubtful[i] AND need[i] freemoney) then // need = claim - loan, how // much process i still needs

finishdoubtful[i] = false ; // process can finish because last_iteration_successful = true // need free resources

free money = free money + loan[i] ; // process is able to finish thus // it will repay the loan back

end if end for End while if (free money == capital) then safe! else not safe! ;

Page 6: Pros and Cons of different strategies Deadlock detection => graph reduction method –Pros: maximum concurrency and resource utilization –Cons: roll-back,

Banker’s algorithm example (1)

• System with 3 processors and 3 resources, and with the following matrices:

• Request F1 = (0 0 1) should be granted?

342matrix Avail-Max A

111

121

221

matrix Claim-Max B

101

110

021

matrix AllocationCurrent C

n

kkCAD

1

110matrix AvailCurrent

CBE

010

011

200

matrix NeedCurrent

Page 7: Pros and Cons of different strategies Deadlock detection => graph reduction method –Pros: maximum concurrency and resource utilization –Cons: roll-back,

Banker’s algorithm example (2)

• Suppose the request is granted, the resulting state would be the following:

101

110

121

matrix AllocationCurrent C

n

kkCAD

1

010matrix AvailCurrent

CBE

010

011

100

matrix NeedCurrent

Page 8: Pros and Cons of different strategies Deadlock detection => graph reduction method –Pros: maximum concurrency and resource utilization –Cons: roll-back,

Banker’s algorithm example (3)

• The new state is safe– P3 can complete (because E3 D) and thus can return

(1 0 1) to the pool of available resources

– D becomes (1 1 1); the outstanding needs of both P1 and P2 can be satisfied