Lec25 CS604 Pps
Lec25 CS604 Pps
Systems
Lecture 25
Syed Mansoor Sarwar
Agenda for Today
Review of previous lecture
Dining philosophers problem
High-level synchronization
constructs
Critical region
Monitor
Recap of lecture
14 September 2019 © Copyright Virtual University of
Pakistan
Review of Lecture 24
Counting semaphores
Classical synchronization
problems
Bounded buffer problem
Shared data
struct buffer {
int pool[n];
int count, in, out;
}
14 September 2019 © Copyright Virtual University of
Pakistan
Producer Process
Producer process inserts
nextp into the shared
buffer
region buffer when (count < n) {
pool[in] = nextp;
in:= (in+1) % n;
count++;
}
14 September 2019 © Copyright Virtual University of
Pakistan
Consumer Process
Consumer process removes
an item from the buffer and
puts it in nextc
region buffer when (count > 0) {
nextc = pool[out];
out = (out+1) % n;
count--;
}
14 September 2019 © Copyright Virtual University of
Pakistan
The region Statement
What happens when two
region statements are
executed simultaneously?
region v when B do S1;
region v when B do S2;
Monitor