Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
language:types2:chan [2024/07/18 16:15] – created rajit | language:types2:chan [2024/07/18 16:23] (current) – [Channel methods] rajit | ||
---|---|---|---|
Line 21: | Line 21: | ||
channel type. | channel type. | ||
+ | ===== Channel methods ===== | ||
+ | |||
+ | |||
+ | There are eight possible methods that can be defined for a channel type: | ||
+ | |||
+ | * Methods for sending and receiving values on the channel | ||
+ | * '' | ||
+ | * '' | ||
+ | * Methods for initializing | ||
+ | * '' | ||
+ | * '' | ||
+ | |||
+ | For channels, there are two special methods that are used for probe operations with different syntax. Both of these have to be specified via an expression, rather than the normal method syntax. | ||
+ | * '' | ||
+ | * '' | ||
+ | |||
+ | The send operation '' | ||
+ | parts: setting the data value, followed by the synchronization | ||
+ | operation, and possibly the reset phase of the handshake. | ||
+ | Setting the data value also indicates that the sender is | ||
+ | ready to communicate. It is illegal to set the data value multiple | ||
+ | times without an intervening synchronization operation. Finally, | ||
+ | attempting to set the data value might block if the previous channel | ||
+ | operation has not completed as yet. Whether or not this could occur | ||
+ | depends on the channel protocol. | ||
+ | |||
+ | The receive operation '' | ||
+ | three parts: receiving the data value, followed by the synchronization | ||
+ | operation, and finally the rest of the handshake. | ||
+ | Attempting to get the data value from the channel will | ||
+ | block if the sender has not provided any value. Once a value has been | ||
+ | extracted from the channel, the synchronization operation can be | ||
+ | executed. Prior to the synchronization, | ||
+ | executed; the channel must be designed so that subsequent get | ||
+ | operations will return the same value as the first one, and will be | ||
+ | guaranteed not to block. The get operation is used to implement a CHP | ||
+ | value probe, where the receiver can peek at the value pending in the | ||
+ | channel without attempting a synchronization operation. | ||
+ | |||
+ | An example definition of a Boolean channel where the channel has an | ||
+ | lazy-active send and passive receive is below. Note that for a channel, | ||
+ | '' | ||
+ | on the channel. | ||
+ | |||
+ | <code act> | ||
+ | defchan e1of2 <: chan(bool) (bool d0,d1,e) | ||
+ | { | ||
+ | spec { | ||
+ | exclhi(d0, | ||
+ | } | ||
+ | | ||
+ | set { | ||
+ | [e]; | ||
+ | } | ||
+ | send_up { | ||
+ | [~e] | ||
+ | } | ||
+ | send_rest { | ||
+ | d0-,d1- | ||
+ | } | ||
+ | get { | ||
+ | | ||
+ | } | ||
+ | recv_up { | ||
+ | e- | ||
+ | } | ||
+ | recv_rest { | ||
+ | | ||
+ | } | ||
+ | recv_probe = (d0|d1); | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | In the example above, the '' | ||
+ | specify the sequence of operations on the channel variables that are | ||
+ | invoked for a send action. The '' | ||
+ | specify the sequence of operations used to perform a receive. The | ||
+ | special variable '' | ||
+ | that is being either sent or received on the channel. | ||
+ | |||
+ | This channel has an active send and passive receive, and hence probes | ||
+ | are only supported at the receiver. The '' | ||
+ | expression specifies the Boolean expression corresponding to the probe | ||
+ | at the receiver end of the channel. A '' | ||
+ | specified in a similar way when the sender is passive and receiver is | ||
+ | active. | ||
+ | |||
+ | The '' | ||
+ | handshake protocol. If the channel were to correspond to a two-phase | ||
+ | protocol, a different sequence of actions can be specified instead. | ||
+ | |||
+ | When defining an exchange channel, the special variable '' | ||
+ | used to specify the value being received by the sender, and being sent by the receiver. | ||