|
Making Connections between Tasks |
Top Previous Next |
|
The CONNECT statement sets up a channel between two tasks, by connecting an output port to an input port. A channel corresponds to one of the thin arrows in the diagram above, and data can move along it in one direction only. This means that we need two CONNECT statements to create two channels for bi-directional communication between driver and upc:
connect ? driver[0] upc[0] ! driver -> upc connect ? upc[0] driver[0] ! upc -> driver
The CONNECT keyword can be followed by an identifier naming the connection, but all the configuration statements which declare new identifiers allow a question mark to be used in place of the identifier being declared. This is useful when there is no need to refer to an object after it has been declared. The identifier declared by a CONNECT statement can be used later in a program to simplify access to the associated channels.
After the identifier (or question mark) we code first the output port, and then the input port. Thus, the first CONNECT statement in the example above makes a channel from driver's output port 0 to upc's input port 0.
Consider the following statement:
connect ? first[2] second[6]
This would allow the following matching statements in the two tasks (assuming the standard declaration of the parameters to main):
first: chan_out_message(sizeof(buffer), buffer, out_ports[2]); second: chan_in_message(sizeof(mybuffer), mybuffer, in_ports[6]); |