Monitor
rns cs
erty
Da ec
+ Synchronization between concurrent procedure invocation
O Conditional Variable provides synchronization
inside the monitor.
CO Ifa process wants to sleep inside the monitor or it
allows a waiting process to continue, in that case
conditional variables are used in monitors.
O Three operations can be performed on conditional
variables
Y wait, signal and broadcast
O Conditional Variable provides synchronization
inside the monitor.
O Ifa process wants to sleep inside the monitor or it
allows a waiting process to continue, in that case
conditional variables are used in monitors.
O Three operations can be performed on conditional
variables
¥ wait, signaland broadcastNTU eM ste Nee ee} (nnn wel] tn
Acquire()
{
if busy then nonbusy.
olse busy=trus -
}
Release()
{
busysfalse
‘nonbusy signal
?
Conditional variable
Tate ee Ng =la | T
monitor bb
{
int data[5)
intcount
condition full
condition empty
produce()
{
if count == @then full.wait
‘add item te Buffer & increase count value
‘empty.signal
}
counsume()
if count ==0 thenempty.wait
access item from buffer and decrease
value ofcount
‘empty.signalProducer Consumer problem using message passing
#define N 100 //number of empty slots
void producer (void)
{
int item;
message m; /Imessage buffer
while (true)
{
item=produce_item(); //generate something to put in buffer
receive(consumer, &m); //wait for an empty to arrive
build_message(&m, item); —//construct a message to send
send(consumer, &m); //send item to consumer
}
Producer Consumer problem using message passing
void consumer (void)
{
int item, i;
message m;
for (i=0; i