![]()
|
NAME
SYNTAX
EXECUTABILITY
EFFECT
DESCRIPTION
The first form of the receive statement is the standard fifo receive. The second form, written with two question marks, is called a random receive statement. The third form, a fifo receive with angle brackets, is called a fifo poll statement. The last form, a random receive with angle brackets, is called a random receive poll , statement. Because all these statements can have side-effects on the variables that appear in the argument lists, they cannot be used inside expressions (but see also poll(5)). EXAMPLES
chan set = [8] of { byte };
byte x;
set!!3; set!!5; set!!2; /* add 3 elements to the set, sorted */
set?x; /* retrieve the smallest element */
if
:: set??[5] /* is there still a 5 in the set? */
:: else
fi
NOTES
It is relatively simple to create a conditional receive operation, using channel poll operations (see poll(5)), if the channel is buffered (i.e., has a non-zero capacity). If the channel is a rendezvous channel, however, this can be more complicated. Consider the following rendezvous arrangement: global: chan port = [0] of { byte };
sender: port!mesg(12)
receiver: port?mesg(data)
We want to define an extra boolean condition
P
that must hold before the rendezvous send operation
becomes executable, and a boolean condition
Q
that must hold
before the matching receive becomes executable.
We can specify this with the help of two additional
rendezvous channels, as follows.
global: chan port[3] = [0] { byte };
sender: port[(1-P)]!mesg(12)
receiver: port[(2-Q)]?mesg(data
When
P
is
false ,
the sender attempts to handshake on
port[1] ,
and when
Q
is
false ,
the receiver attempts to handshake on
port[2] .
Only when both
P
and
Q
are
true
can sender and receiver handshake via
port[0] .
SEE ALSO
|