auss of dadloks Four ssary oditios for dadlok to our ar: Exlusiv ass: prosss rquir xlusiv ass to a rsour Wait whil hold: prosss hold o prviously aquird rsours whil waitig for additioal rsours No prmptio: a rsours aot prmptd from a pross without aortig th pross irular wait: thr is a st of lokd prosss ivolvd i a irular wait Th first thr proprtis ar grally dsiral rsptivly to i) prsrv rsour itgrity, ii) iras rsour utilizatio, iii) rdu wast of PU tim
Dadlok hadlig poliis Dadlok prvtio th systm is dsigd so that gratig rqusts vr lads to a dadlok Dadlok dttio th systm priodially (or wh dadlok susptd) hks for dadloks, ad a rovry produr is startd if o is dttd Dadlok avoida rsours ar gratd oly if th rsultig systm stat is saf i.. thr is at last o squ of xutio i whih all prosss ru to ompltio
akr s algorithm Dfiitios for a systm with prossors ad m rsours: ( ) a m a a matrix - vail Max m m m Max - laim matrix m m m urrt lloatio matrix ( ) k m k d d d D matrix vail urrt m m m E E E E urrt Nd matrix ( ) i m i i i f f f F tor Rqust v
lgorithm stps Stp - ttativ apt of rqust D : D - F // updat urrt vail matrix D i : i + F i // updat urrt llo vtor i E i : E i - F i // updat urrt Nd matrix E i Stp - saf-stat hkig tst s xt slid i whih frmoy D loa[i] i d[i] E i Stp 3 - if tst positiv dfiitiv apt of rqust, othrwis roll ak th updats of stp
akr at work: saf-stat hkig Whil (last_itratio_sussful) last_itratio_sussful fals ; for i to N do if (fiishdoutful[i] ND d[i] frmoy) th // d laim - loa, how // muh pross i still ds fiishdoutful[i] fals ; last_itratio_sussful tru fr moy fr moy + loa[i] ; // pross a fiish aus // d fr rsours // pross is al to fiish thus // it will rpay th loa ak d if d for Ed whil if (fr moy apital) th saf! ls ot saf! ;
akr s algorithm xampl () Systm with 3 prossors ad 3 rsours, ad with th followig matris: Rqust F ( ) should gratd? ( ) 3 4 matrix - vail Max - laim matrix Max lloatio matrix urrt ( ) k k D matrix urrt vail E urrt Nd matrix
akr s algorithm xampl () Suppos th rqust is gratd, th rsultig stat would th followig: lloatio matrix urrt ( ) k k D matrix urrt vail E urrt Nd matrix
akr s algorithm xampl (3) Th w stat is saf P 3 a omplt (aus E 3 D) ad thus a rtur ( ) to th pool of availal rsours D oms ( ); th outstadig ds of oth P ad P a satisfid
Dadlok aalysis Dadlok aalysis is ompliatd y th umr of variats of th pross-rsour rlatioship how may ad xatly whih rsours ar dd? How may tims a rsour a usd? How may prosss a simultaously us a rsour? W will study: simpl modls usd to rprsts rqusts ad rsour typs Irasigly sophistiatd graph-asd thiqus for dadlok aalysis
Modls of dadlok Dpdig o th typ of rsour rqust, a dadlok a lassifid aordig to o of four typs Sigl-uit rqust modl: vailla varity ND rqust modl: I d a PU ND a disk ND a pritr OR rqust modl: I d a disk OR a pritr ND-OR rqust modl: I d a PU ND (a disk OR a pritr)... P-out-of-Q rqust modl: I d at last thr ossus vots out of fiv
Wait-for-graph (WFG) To study dadloks th stat of a systm is oft rprstd with a wait-for graph p i p j p i ds a rsour hld y p j yl i th graph rprsts a irular wait
Dfiitio of kot kot of a graph is a sust K of ods suh that th rahal st of ah od i K is xatly K Exampls: D D,, ar i a yl ad also i a kot,, ar i a yl, ot i a kot
Modl diffrs Sigl-uit rqust modl: a dadlok orrspods to a yl i th WFG ND rqust modl: sam as aov (if vry rsour is i sigl opy), ut a pross ow a ivolvd i mor tha o dadlok OR rqust modl: a kot is a suffiit oditio for a dadlok ND-OR rqust modl: a kot is a suffiit oditio for a dadlok P-out-of-Q rqust modl: a kot is a suffiit oditio for a dadlok