1
Administrivia
Assignments 0 & 1 Class contact f or the next two weeks Next week
midt er m exam pr oj ect r eview & discussion (Chr is Chamber s)
Following week
Memor y Management (Wuchi Feng)
Administrivia Assignments 0 & 1 Class contact f or the next two - - PowerPoint PPT Presentation
Administrivia Assignments 0 & 1 Class contact f or the next two weeks Next week midt er m exam pr oj ect r eview & discussion (Chr is Chamber s) Following week Memor y Management (Wuchi Feng) 1 CSE 513 I
1
Assignments 0 & 1 Class contact f or the next two weeks Next week
midt er m exam pr oj ect r eview & discussion (Chr is Chamber s)
Following week
Memor y Management (Wuchi Feng)
2
3
A binary semaphore can only take on the values
Class exercise: create a counting semaphore
4
5
I t is dif f icult to produce correct programs using
cor r ect or der ing of up and down is t r icky! avoiding deadlock is t r icky! boundar y condit ions ar e t r icky!
Can we get the compiler to generate the
what ar e suit able higher level abst r act ions f or
6
Local dat a variables are accessible only via t he monit or’s
P
Only one process may execut e wit hin t he monit or at a
Wait (cv) – process blocked (queued) unt il condit ion holds Signal(cv) – signals t he condit ion and unblocks (dequeues)
7
8
9
10
must not block holding t he mut ex, so what t o do when a
signals are not st ored if signal occurs bef ore wait , signal is lost !
11
A wait s f or B t o exit t he monit or or blocks again B wait s f or A t o exit t he monit or or block Signal causes A t o immediat ely exit t he monit or or block
B is unblocked, but C remains blocked C is unblocked, but B remains blocked
a new ext ernal process is allowed t o ent er but which one?
12
Hoare semantics
On signal, allow signaled pr ocess t o r un; upon it s
Brinch Hansen semantics
signaler must immediat ely exit f ollowing signal
13
I nterprocess communication
via shar ed memor y acr oss machine boundar ies
Message passing can be used locally or remotely
pr ocesses use send and receive pr imit ives r eceive can block like wait send unblocks a pr ocess blocked on r eceive (like
14
15
Mailboxes
syst em maint ains a buf f er of sent , but not yet
Rendezvous
sender and r eceiver must be act ive at t he same
r eceive must be blocked bef or e send occur s ker nel does no buf f er ing when does t he send r et ur n?
16
Use of a barrier
pr ocesses appr oaching a bar r ier all pr ocesses but one blocked at bar r ier last pr ocess ar r ives, all ar e let t hr ough
17
18
print ers t ape drives kernel dat a st ruct ures (process & f ile t able ent ries …
locks/ semaphores t o prot ect crit ical sect ions
at t he same t ime anot her process holds B and request s A bot h are blocked and remain so …
19
20
Preemptable resources
can be t aken away f r om a pr ocess wit h no ill ef f ect s
Nonpreemptable resources
will cause t he pr ocess t o f ail if t aken away
Deadlocks occur when processes are granted
21
be awakened run release resources
22
Mut ual exclusion condit ion – resource assigned t o one
Hold and wait condit ion – processes can get more t han
No preempt ion condit ion Circular wait condit ion – chain of t wo or more processes
23
24
25
Not so bad
Pr ogr ammer cr eat es a sit uat ion t hat deadlocks Kill t he pr ogr am and move on
Worse
Spin locks and locking mechanisms wit hin t he OS
26
27
Resource Allocation Graphs (RAGs) Resource R assigned to process A Process B waiting f or resource S Process C and D are deadlocked over T & U
28
Four general strategies
I gnor e t he pr oblem
Det ect ion and r ecover y Dynamic avoidance t hr ough r esour ce allocat ion Pr event ion, by st r uct ur ally negat ing one of t he
29
Let the problem happen, then recover How do you know it happened? Do a depth- f irst- search on the resource
30
Let the problem happen, then recover How do you know it happened? Do a depth- f irst- search on the resource
31
Let the problem happen, then recover How do you know it happened? Do a depth- f irst- search on the resource
32
Let the problem happen, then recover How do you know it happened? Do a depth- f irst- search on the resource
33
Let the problem happen, then recover How do you know it happened? Do a depth- f irst- search on the resource
34
Theorem: I f a graph does not contain a cycle
A cycle in a RAG is a necessar y condit ion f or
I s the existence of a cycle a suf f icient
35
Theorem: I f a graph does not contain a cycle
A cycle in a RAG is a necessar y condit ion f or
I s the existence of a cycle a suf f icient
36
37
38
39
I s there a sequence of running process such
40
41
42
43
44
45
46
47
48
How of ten should the algorithm run?
Af t er ever y r esour ce r equest ? Per iodically? When CPU ut ilizat ion is low? When we suspect deadlock?
49
What should be done to recover?
Abor t deadlocked pr ocesses and r eclaim r esour ces Tempor ar ily r eclaim r esour ce, if possible Abor t one pr ocess at a t ime unt il deadlock cycle is
Wher e t o st ar t ?
50
Recovery through rollback
Save st at e per iodically
Done f or lar ge comput at ion syst ems
51
Detection vs. avoidance…
Det ect ion – “opt imist ic” appr oach
Avoidance – “pessimist ic” appr oach
Which one t o use depends upon t he applicat ion
52
53
54
Saf e state – “when system is not deadlocked
55
56
57
Maximum Request Vector
Row 2 is what process 2 might need
58
Ma x re que st ma trix
59
Ma x re que st ma trix
60
Ma x re que st ma trix
61
Ma x re que st ma trix
62
Ma x re que st ma trix
63
Ma x re que st ma trix
64
Deadlock avoidance is usually impossible
because you don’t know in advance what r esour ces a
Alternative approach “deadlock prevention”
Pr event t he sit uat ion in which deadlock might occur
At t ack one of t he f our condit ions t hat ar e
65
Attacking mutual exclusion?
a bad idea f or some r esour ce t ypes may wor k f or ot her s
Attacking no preemption?
a bad idea f or some r esour ce t ypes may wor k f or ot her s
66
Attacking hold and wait
have pr ocesses r equest all r esour ces bef or e
if new r equest , deallocat e and r eallocat e!
67
Attacking circular wait
same pr oblem/ solut ion in t he dining philosopher s number all r esour ces and acquir e in t he same or der may be har d t o get an or der ing t hat ever yone likes
68
Attacking circular wait
Same pr oblem in t he dining philosopher s Number all r esour ces Typically har d t o get an or der ing t hat ever yone
69
Attacking circular wait
Same pr oblem in t he dining philosopher s Number all r esour ces Typically har d t o get an or der ing t hat ever yone
70
Starvation and deadlock are two dif f erent
Wit h deadlock – no wor k is being accomplished f or
Wit h st ar vat ion – wor k (pr ogr ess) is get t ing done,
71
What is deadlock? Deadlock detection algorithms Read
Chapt er 3 Sample pr oblems
72