Next: , Up: CHP Statements


14.3.1 Communications

To receive data over a channel, one simply writes:

For example, X?(x, w) means: receive values x and w over the two fields of channel X.

To send data over a channel, one writes:

For example, Y!(y, z) means: send values y and z over the two fields of channel Y.

The channels referenced in sends and receives may be either fundamental channel types or user-defined channel types. However, the channel reference must be scalar (0-dimensional). The variables in the reference list or expression list must type-check against the fields of the underlying fundamental channel type. See Fundamental Channel Types, regarding fundamental channel types. If any types are template-parameter dependent, then type-checking is deferred until the template types have been instantiated.

Operational semantics: Sends and receives in CHP have blocking semantics, i.e., a communication does not complete until its complement (the other side) is also reached. After both sides of the communication have `synchronized,' can the communication proceed.

Execution clarification: Suppose we have the statement X[i]!(y[j]), where i and j are nonmeta (run-time) variables. If we reach this program point, and find that X[i] is blocked (not ready to send), then we must suspend further execution until one of the following conditions changes:

If we were to be precise, and track dependencies dynamically (rather than conservatively and statically), we could narrow the first conditional to only X[i] receiving. Only at the time of execution, do we evaluate the value of y[j] for sending. The value and reference of y[j] is permitted to change between the time it is blocked and the time the communication is executed! (Can we trap or alert when this is not intended?)

TODO: Probes (implemented, but not documented yet)