Operating System Concepts and Techniques Lecture 14 Interprocess communication-3 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques, irst ed., iUniverse Inc., 2011. To order: www.iUniverse.com , www.barnesandnoble.com, or www.amazon.com
16
Embed
Operating System Concepts and Techniques Lecture 14
Operating System Concepts and Techniques Lecture 14. Interprocess communication-3 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques, irst ed., iUniverse Inc., 2011. To order: www.iUniverse.com , www.barnesandnoble.com, or www.amazon.com. - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Operating System Concepts and
Techniques Lecture 14
Interprocess communication-3
M. Naghibzadeh
ReferenceM. Naghibzadeh, Operating System Concepts and Techniques, irst ed., iUniverse Inc., 2011.
To order: www.iUniverse.com, www.barnesandnoble.com, or www.amazon.com
Message is mainly used for information interchange between in distributed
systems, however, it can be used within standalone computers
There are two main system calls, send and receive; usually with the following
format send (source, destination, message)
receive (source, destination, message)
8
Blocking/Non-blockingSending/receiving could be blocking or non-
blocking; we are interested in non-blocking send and blocking receive
Blocking send: The execution of the sender process is suspended until the message is delivered and the receiver
informs the sender of the matter Nonblocking send: The sender executes the send and
continues its execution; The sender will not become aware of whether or not the message was actually delivered
Blocking receive: The receiver(s) executes a receive and waits until the message is fully received before proceeding
Non-blocking receive: The receiver executes a receive and continues its execution; if the message is available it is received, otherwise, when the message is received the kernel will send an
interrupt to the corresponding receiver process informing it of the receipt of message
9
How to enforce mutual exclusion
Suppose we have a common mailbox with one message in it
Whichever process grabs the message is allowed to use the critical resource
After the execution of its critical section, the process sends back the message to the
mailboxProper send and receive statements for this
purpose would be: receive (mailbox, message)
send (mailbox, message)
10
The producer procedureThe following is the initialization and
the producer#define true 1
#define BC 1000 // Buffer capacity void producer (void)
{ struct buffer_slot entity;
message msg1, msg2; while (true) {
produce_an_entity(&entity); receive (consumer, producer, &msg1); //Wait for consumer’s message
receive (mailbox,&msg2); //Get permission to use the entity-queue insert_the_entity(&entity); //Put entity in queue
send (mailbox, &msg2); //Free the resource, i.e., queue send (producer, consumer,&msg1); //One slot is filled
}}
11
The consumer procedurevoid consumer (void)
{ struct buffer_slot entity;
message msg1, msg2; for (i=0; i<BC; i++) send (consumer, producer, &msg1); //BC slots are
free while (true) {
receive (producer, consumer, &msg1); //Wait until there is an entity