|
NAME
SYNTAX
DESCRIPTION
A single keyword chan can be followed by either a single name, or a comma-separated list of names, each optionally followed by a channel initializer. The syntax chan a, b; chan c[3]declares the names a , b , and c as channel names, the last one as an array of three elements (see arrays(2)). A channel must be initialized before it can be used to store messages. It is rare to declare just a channel name without initialization, but it occurs in, for instance, proctype parameter lists, where the initialized version of a channel is not passed to the process until the time of process instantiation with a run operator. The channel initializer specifies a channel capacity, as a constant, and the structure of the messages that can be stored in the channel, as a comma-separated list of type names. If the capacity is larger than zero, a normal buffered channel is initialized, with the given number of slots to store messages. If the capacity is specified to be zero, a rendezvous , also called a synchronous , channel, is created. Rendezvous channels can pass messages only through synchronous handshakes between sender and receiver, but they cannot buffer messages (see send(4), receive(4)). EXAMPLES
The following channel declaration contains an initializer. chan a = [16] of { short }The initializer says that channel a can store up to sixteen messages of type short . Similarly, chan c[3] = [0] of { mtype }initializes an array of 3 rendezvous channels for messages that contain just one message field, of type mtype . If the messages to be passed by the channel have more than one field, the declaration looks as follows: chan qname = [8] of { mtype, int, chan, byte }This time, we have defined a single channel that can store up to eight messages, each consisting of four fields: an mtype , followed by an int , followed by a channel name, and a byte . The chan field can be used to pass a channel identifier (a number) from one process to another. NOTES
In verification, buffered channels contribute significantly to verification complexity. For an initial verification run, choose a small channel capacity, of say 2 or 4. If the verification completes swiftly, you can consider increasing the capacity to a larger size. SEE ALSO
|