PROTOCOLS (CONT)
CHAN of INT :: [] REAL Ch :
above is defined a channel through which elements of the REAL type are to be transferred, number of elements is transferred at first as data of INT type.
In the next example one process sends segment of an array and the second process receives it using declared above channel:
Ch! 17 :: [A from 0 for 17] -- sender
Ch? len :: [B from 20 for len] –- receiver
SEQUENTIAL PROTOCOLS
Protocol can be defined explicitly by the following construction:
PROTOCOL protocol_name IS name-1; name-2; …; name-N: where name-i, i=1,N, defines some predefined or standard simple protocol; afterwards already defined protocol may be used for channel declaration:
CHAN OF <protocol name > <channel name >:
For instance,
PROTOCOL Dimensions IS Real32; Real32; Real32:
CHAN OF Dimensions Measurements: defines sequential protocol of sending and receiving of three real numbers for the channel Measurements.
23
PROTOCOLS (CONT)
Variant protocols are used in the cases when it is necessary to send data into the channel in different formats in different moments of the time.
To each format is assigned corresponding tag, which is sent into the channel before data transmission to acknowledge counterpart side about used format of sending.
Variant protocol is defined as follows:
PROTOCOL protocol_name
CASE tag1; sequence1 – sequence of simple protocols’ names, separated by «;»
.
. tagN; sequenceN:
For example, protocol
PROTOCOL IO
CASE
Fixed: INT
Float: REAL32
: describes variable protocol using which tag integer values will be transferred with preceding tag Fixed and tag Float will be output in corresponding channel before real number.
CHAN of IO Ch: --describes channel Ch, working according to protocol IO
24
56
PROTOCOLS (CONT)
In the following fragment values 1 and 2.14 are output into Ch with preceding tag values, which are to be received and recognized by counterpart side:
Ch! fixed; 1 (INT)
Ch! float; 2.14 (REAL32)
Ch? case
Fixed; i
Was.INT:= TRUE
Float; x:
Was.INT:=FALSE
ANARCHIC PROTOCOLS
Anarchic protocols are used when synchronization of processes is necessary, they need in signals exchanging only and form of representation of these signals is not important.
Anarchic channel ch is defined in the following line:
CHAN of any ch:
Input and output using anarchic channels is made as follows:
Ch! any -- output
Ch? any – input
25
TIMERS
Timer in Occam language is a special channel with a simple protocol int. Number of timers is not restricted. Timers are declared as follows:
TIMER t:
name t is declared with the TIMER type
Timers may be used only for reading:
T ? time -- variable time gets current value of timer t
Timer is always ready for input from them. It outputs current value of the counter which is incremented with each tick of the transputer physical timer
(in Т805 – each microsecond).
Interval timer
Is implemented in Occam with the help of the construction AFTER:
Name?AFTER expression, where Name is the name of the timer, expression determines counter value unless achieving of which process is suspended.
26
TIMERS (CONT)
Timer’s counter after achieving maximal value is thrown to 0 and after that is incremented again. Module operations are used in the expression for interval timer for taking into account this circumstance.
For instance, the following fragment can be used for process suspension during one minute:
VAL TicksPerSecond IS 1000000:
VAL OneMinute IS 60*TicksPerSecond:
TIMER Clock:
SEQ
Clock?Now
Clock? AFTER Now PLUS OneMinute
27