120 likes | 227 Views
Detecting Deadlock Multiple resources of each type Adapted From Satya, 15-412 Fall ‘99. E =. e 0 e 1 e 2 … e n-1. Entirety. Initial State. n resources. E =. e 0 e 1 e 2 … e n-1. Entirety. A =. a 0 a 1 a 2 … a n-1. Available. c 0 0 c 0 1 c 0 2 … c 0 n-1
E N D
Detecting DeadlockMultiple resources of each typeAdapted From Satya, 15-412 Fall ‘99
E = e0 e1 e2 … en-1 Entirety Initial State n resources
E = e0 e1 e2 … en-1 Entirety A = a0 a1 a2 … an-1 Available c00 c01 c02 … c0n-1 c10 c11 … c1n-1 … cij… cm-10cm-11 cm-12 … cm-1n-1 C = Current At Any Point n resources m processes
n resources r00 r01 r02 … r0n-1 r10 r11 … r1n-1 … rij… rm-10rm-11 rm-12 … rm-1n-1 R = Request New Request m processes
Testing for Deadlock • while ( unmarked rows exist inR ) { • find unmarked rowkinRsuch thatRkA • if ( no such row found ) • { report deadlock and quit} • else { • mark rowk; /* this process’ request can be granted */ • A+= Ck; /* held resources will be returned finally */ • } • } • if we reach here, there is no deadlock
n resources A = a0 a1 a2 … an-1 Available r00 r01 r02 … r0n-1 r10 r11 … r1n-1 … rij… rm-10rm-11 rm-12 … rm-1n-1 R = Request Example: R1A m processes
Dynamic Deadlock Avoidance Banker’s algorithm Adapted From Satya, 15-412 Fall ‘99
E = e0 e1 e2 … en-1 Entirety l00 l01 l02 … l0n-1 l10 l11 … l1n-1 … cij… lm-10lm-11 lm-12 … lm-1n-1 L = Line of credit Initial State n resources m processes
E = e0 e1 e2 … en-1 Entirety A = a0 a1 a2 … an-1 Available c00 c01 c02 … c0n-1 c10 c11 … c1n-1 … cij… cm-10cm-11 cm-12 … cm-1n-1 C = Current At Any Point n resources m processes
Residual Credit R = L - C r00 r01 r02 … r0n-1 r10 r11 … r1n-1 … rij… rm-10rm-11 rm-12 … rm-1n-1 R = Residual Credit
n resources N = n0 n1 n2 … nn-1 New Request by Process i
Is it Safe to Allocate N? • Pretend request is granted • Update state variables • Ci = Ci + N • Ri= Ri- N • A = A - N • Run deadlock detection with C, R, A • no deadlock allocation safe • deadlock allocation unsafe; • undo changes to C, R, A • block process I until A increases, then retry