CHP Communications - The HAC Language
Description: The HAC Language

Next: CHP Assignments, Up: CHP Statements

#### 14.3.1 Communications

To receive data over a channel, one simply writes:

- CHP-receive : channel-reference `?` `(` data-reference-list `)`

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:

- CHP-send : channel-reference `!` `(` nonmeta-expr-list `)`

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:

- `X[k]` receive executes for some value `k`
- `i` changes the reference to a different channel

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)