Professional Documents
Culture Documents
• Monitors
equivalent functionality of semaphores
easier to control.
Monitor Characteristics
mutual exclusion
Monitor as an object.
Monitor Module
• Procedures
• Initialization sequence
• Local data
Synchronization
Operated by functions
consumer will not even be let into the monitor until the WAIT is finished
•Acknowledgement.
•Retransmission – duplication.
•Process naming
•Authentication.
void producer(void) {
int item;
message m; /* message buffer */
while (TRUE) {
produce-item(&item); /* generate something to put in buffer */
receive(consumer&, m); I* wait for an empty to arrive *I
build-message(&m, item); /* construct a message to send */
send(consumer, &m); /* send item to consumer *I
}
}
void consumer(void) {
int item, i;
•Faster procedure message m;
blocked. for (i = 0; i < N; i++) send(producer, &m); /* send N empties */
•Waiting for empty while (TRUE) {
to come. receive(producer, &m); /* get message containing item *I
•Faster consumer extract-item(&m, &item); I* extract item from message *I
send(producer, &m); I* send back empty reply *I
waiting consume-item(item); /* do something with the item */
for procedure }
to fill up.
}
Message passing - Variants