next up previous
Next: About this document Up: Process Coordination Previous: Path Expressions

Synchronous Message Passing

Synchronous message passing offers another mechanism for process synchronization. To illustrate, a bounded buffer can be defined using message-passing primitives. The buffer is managed by a special ``bounded buffer'' process, with which producers and consumers communicate to produce and consume buffers, respectively:

{\bf loop}
	{\bf select}
		{\bf when} count > 0 {\bf receive} GetBuffer (...) ...
		{\bf when} count < size {\bf receive} PutBuffer (...) ...
	{\bf end}
{\bf end loop}.
Here we are assuming RPC, select, and guards. The process defines two input ports, one for producers and another for consumers, and uses select to receive both produce and consume requests. The variable count keeps the number of filled buffers. A consuming process is blocked if the buffer is empty and a producing process is blocked if it is full.

Notice a process executing such a loop statement is similar to a monitor. Each receive in an arm of a select corresponds to an entry procedure declaration in a monitor. A process services one receive at a time, just as a monitor executes one entry procedure at a time. The guards correspond to waits on conditions.

Prasun Dewan
Wed Oct 16 15:58:47 EDT 1996