Upload
farrukh-tahir
View
245
Download
0
Embed Size (px)
Citation preview
7/26/2019 Chap#06 Deadlocks
1/27
MODERN OPERATING SYSTEMS
Chapter 6
Deadlocks
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Ha, !nc" # rig$ts reser%ed" 0-&3-6006639
7/26/2019 Chap#06 Deadlocks
2/27
Preemptable and Nonpreemptable
Resorces
Se!ence o" e#ents re!$red to se a
resorce%
&' Re!est the resorce'(' )se the resorce'
*' Release the resorce'
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Ha, !nc" # rig$ts reser%ed" 0-&3-6006639
7/26/2019 Chap#06 Deadlocks
3/27
+$,re 6-&' )s$n, a semaphore to protect resorces'
.a/ One resorce' .b/ T0o resorces'
Resorce Ac!$s$t$on .&/
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Ha, !nc" # rig$ts reser%ed" 0-&3-6006639
7/26/2019 Chap#06 Deadlocks
4/27
+$,re 6-(' .a/
Deadlock-"ree
code'
Resorce Ac!$s$t$on .(/
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Ha, !nc" # rig$ts reser%ed" 0-&3-6006639
7/26/2019 Chap#06 Deadlocks
5/27
+$,re 6-(' .b/ Code 0$th a
potent$al deadlock'
Resorce Ac!$s$t$on .*/
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Ha, !nc" # rig$ts reser%ed" 0-&3-6006639
7/26/2019 Chap#06 Deadlocks
6/27
Introdct$on To Deadlocks
Deadlock can be de"$ned "ormall1 as
"ollo0s%
A set of processes is deadlocked if eachprocess in the set is waiting for an event
that only another process in the set can
cause.
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Ha, !nc" # rig$ts reser%ed" 0-&3-6006639
7/26/2019 Chap#06 Deadlocks
7/27
Cond$t$ons "or Resorce Deadlocks
&' Mtal e2cls$on cond$t$on
(' 3old and 0a$t cond$t$on'
*' No preempt$on cond$t$on'4' C$rclar 0a$t cond$t$on'
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Ha, !nc" # rig$ts reser%ed" 0-&3-6006639
7/26/2019 Chap#06 Deadlocks
8/27
Deadlock Model$n,
Strate,$es "or deal$n, 0$th deadlocks%
&' 5st $,nore the problem'
(' Detect$on and reco#er1' et deadlocks
occr7 detect them7 take act$on'
*' D1nam$c a#o$dance b1 care"l resorce
allocat$on'
4' Pre#ent$on7 b1 strctrall1 ne,at$n, oneo" the "or re!$red cond$t$ons'
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Ha, !nc" # rig$ts reser%ed" 0-&3-6006639
7/26/2019 Chap#06 Deadlocks
9/27
+$,re 6-8' .a/ A resorce ,raph' .b/ A c1cle e2tracted "rom .a/'
Deadlock Detect$on 0$th
One Resorce o" Each T1pe .&/
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Ha, !nc" # rig$ts reser%ed" 0-&3-6006639
7/26/2019 Chap#06 Deadlocks
10/27
Deadlock Detect$on 0$th
One Resorce o" Each T1pe .(/
Al,or$thm "or detect$n, deadlock%
&' +or each node7 N $n the ,raph7 per"orm the
"ollo0$n, "$#e steps 0$th N as the start$n, node'
(' In$t$al$9e to the empt1 l$st7 des$,nate all arcsas nmarked'
*' Add crrent node to end o" 7 check to see $"
node no0 appears $n t0o t$mes' I" $t does7
,raph conta$ns a c1cle .l$sted $n /7 al,or$thmterm$nates'
:
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Ha, !nc" # rig$ts reser%ed" 0-&3-6006639
7/26/2019 Chap#06 Deadlocks
11/27
Deadlock Detect$on 0$th
One Resorce o" Each T1pe .*/
4' +rom ,$#en node7 see $" an1 nmarkedot,o$n, arcs' I" so7 ,o to step 8; $" not7 ,o to
step 6'
8' P$ck an nmarked ot,o$n, arc at random andmark $t' Then "ollo0 $t to the ne0 crrent node
and ,o to step *'
6' I" th$s $s $n$t$al node7 ,raph does not conta$n an1
c1cles7 al,or$thm term$nates' Other0$se7 deadend' Remo#e $t7 ,o back to pre#$os node7
make that one crrent node7 ,o to step *'
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Ha, !nc" # rig$ts reser%ed" 0-&3-6006639
7/26/2019 Chap#06 Deadlocks
12/27
+$,re 6-6' The "or data strctres needed
b1 the deadlock detect$on al,or$thm'
Deadlock Detect$on 0$th Mlt$ple
Resorces o" Each T1pe .&/
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Ha, !nc" # rig$ts reser%ed" 0-&3-6006639
7/26/2019 Chap#06 Deadlocks
13/27
Deadlock Detect$on 0$th Mlt$ple
Resorces o" Each T1pe .(/
Deadlock detect$on al,or$thm%
&' ook "or an nmarked process7 Pi7 "or 0h$ch
the $-th ro0 o" R$s less than or e!al toA'
(' I" sch a process $s "ond7 add the i-thro0 o" C
toA7 mark the process7 and ,o back to step &'
*' I" no sch process e2$sts7 the al,or$thm
term$nates'
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Ha, !nc" # rig$ts reser%ed" 0-&3-6006639
7/26/2019 Chap#06 Deadlocks
14/27
+$,re 6-
7/26/2019 Chap#06 Deadlocks
15/27
Reco#er1 "rom Deadlock
= Reco#er1 thro,h preempt$on
= Reco#er1 thro,h rollback
= Reco#er1 thro,h k$ll$n, processes
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Ha, !nc" # rig$ts reser%ed" 0-&3-6006639
7/26/2019 Chap#06 Deadlocks
16/27
+$,re 6->' T0o process resorce tra?ector$es'
Deadlock A#o$dance
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Ha, !nc" # rig$ts reser%ed" 0-&3-6006639
7/26/2019 Chap#06 Deadlocks
17/27
+$,re 6-@' Demonstrat$on that the state $n .a/ $s sa"e'
Sa"e and )nsa"e States .&/
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Ha, !nc" # rig$ts reser%ed" 0-&3-6006639
7/26/2019 Chap#06 Deadlocks
18/27
+$,re 6-&' Demonstrat$on that the state $n .b/ $s not sa"e'
Sa"e and )nsa"e States .(/
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Ha, !nc" # rig$ts reser%ed" 0-&3-6006639
Th B k Al $th
7/26/2019 Chap#06 Deadlocks
19/27
+$,re 6-&&' Three resorce allocat$on states%
.a/ Sa"e' .b/ Sa"e' .c/ )nsa"e'
The Bankers Al,or$thm
"or a S$n,le Resorce
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Ha, !nc" # rig$ts reser%ed" 0-&3-6006639
Th B k Al $th
7/26/2019 Chap#06 Deadlocks
20/27
+$,re 6-&(' The bankers al,or$thm 0$th mlt$ple resorces'
The Bankers Al,or$thm
"or Mlt$ple Resorces .&/
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Ha, !nc" # rig$ts reser%ed" 0-&3-6006639
Th B k Al $th
7/26/2019 Chap#06 Deadlocks
21/27
The Bankers Al,or$thm
"or Mlt$ple Resorces .(/
Al,or$thm "or check$n, to see $" a state $s sa"e%
&' ook "or ro07 R7 0hose nmet resorce needs all
A' I" no sch ro0 e2$sts7 s1stem 0$ll e#entall1
deadlock s$nce no process can rn to complet$on
(' Assme process o" ro0 chosen re!ests all resorces$t needs and "$n$shes' Mark process as term$nated7 add
all $ts resorces to the A #ector'
*' Repeat steps & and ( nt$l e$ther all processes marked
term$nated .$n$t$al state 0as sa"e/ or no process le"t0hose resorce needs can be met .there $s a
deadlock/'
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Ha, !nc" # rig$ts reser%ed" 0-&3-6006639
7/26/2019 Chap#06 Deadlocks
22/27
Deadlock Pre#ent$on
= Attack$n, the mtal e2cls$on cond$t$on
= Attack$n, the hold and 0a$t cond$t$on
= Attack$n, the no preempt$on cond$t$on
= Attack$n, the c$rclar 0a$t cond$t$on
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Ha, !nc" # rig$ts reser%ed" 0-&3-6006639
Att k$ th
7/26/2019 Chap#06 Deadlocks
23/27
+$,re 6-&*' .a/ Nmer$call1 ordered resorces'
.b/ A resorce ,raph'
Attack$n, the
C$rclar a$t Cond$t$on
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Ha, !nc" # rig$ts reser%ed" 0-&3-6006639
7/26/2019 Chap#06 Deadlocks
24/27
+$,re 6-&4' Smmar1 o" approaches to deadlock pre#ent$on'
Approaches to Deadlock Pre#ent$on
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Ha, !nc" # rig$ts reser%ed" 0-&3-6006639
7/26/2019 Chap#06 Deadlocks
25/27
Other Isses
= T0o-phase lock$n,
= Commn$cat$on deadlocks
= $#elock= Star#at$on
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Ha, !nc" # rig$ts reser%ed" 0-&3-6006639
7/26/2019 Chap#06 Deadlocks
26/27
+$,re 6-&8' A resorce deadlock $n a net0ork'
Commn$cat$on Deadlocks
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Ha, !nc" # rig$ts reser%ed" 0-&3-6006639
7/26/2019 Chap#06 Deadlocks
27/27
+$,re 6-&6' Bs1 0a$t$n, that can lead to l$#elock'
$#elock