Message Passing
First came across in my first internship at Blackberry QNX. I’ve implemented easy message passing in QNX.
The actual function of message passing is provided in the form of a pair of primitives:
A process sends information in the form of a message to another process designated by a destination. A process receives information by executing the primitive, the source and the message.
Synchronization
Need some synchronization for communication between two processes: The receiver cannot receive a message until it has been sent by another process. Need to also specify what happens to a process after it issues a or .
Combinations:
- Blocking send, blocking receive: Rendez-vous kinda situation
- Nonblocking send, blocking receive: Most useful one. Sender may continue on, the receiver is blocked until the requested message arrives. It allows a process to send one or more messages to a variety of destination as quickly as possible. A process that must receive a message before it can do useful work needs to be blocked until such a message arrives.
- Nonblocking send, nonblocking receive: Neither party is required to wait.
Addressing
todo Direct addressing
Indirect addressing
Message Format
Mutual Exclusion
Assume nonblocking send and blocking receive:
Now, a solution to the bounded-buffer Producer and Consumer Problem: Two mailboxes are used.
As the producer generates data, it is sent as messages to the mailbox . As long as there is at least one message in that mailbox, the consumer can consume. Hence serves as the buffer; the data in the buffer are organized as a queue of messages. The “size” of the buffer is determined by the global variable capacity. Initially, the mailbox is filled with a number of null messages equal to the capacity of the buffer. The number of messages in shrinks with each production and grows with each consumption.