====== Priorities ======
Priorities range from 0 to 9. Zero is the higher system priority. Alvis uses static priorities. The default agent's priority is 0. The priority of an agent is put inside round brackets after the agent name, e.g.:
agent Buffer(9) {
-- ...
}
====== Select statement ======
Syntax:
select {
alt (g1) {...}
alt (g2) {...}
...
}
The **select** statement provides a selective wait for one or more alternatives. The statement may contain a series of **alt** clauses called **branches**. Each branch may be guarded. These guards divide branches into **open** and **closed** ones. A branch is called **open**, if it does not have a guard attached or its guard evaluates to **True**. Otherwise, a branch is called **closed**. To avoid indeterminism, if more than one branch is open the first of them is chosen to be executed. If all branches are closed, the corresponding agent is postponed until at least one branch is open.
select {
alt (g1) {...}
alt (g2) {...}
alt (delay ms) {...}
}
A branch may contain the **delay** function as its guard (In this case **delay** is not a one-step statement, but a function that provides a Boolean result.). In such a case, the third branch will be open after ''ms'' milliseconds. Thus, if all branches are closed, the corresponding agent waits ''ms'' milliseconds and follows the last branch. However, if at least one branch is open before the delay goes by, then the delay is cancelled.
Very often the **ready** function is used as a guard. The function takes a list of agent ports' names with in/out directions and returns **True** if at least one of them is ready for a communication immediately. For example, the guard (''a'' and ''b'' are ports of the corresponding agent):
ready [in(a), in(b)]
evaluates to **True** if the agent can collect immediately a signal/value from at least one of these ports -- It means that another agent has already provided a signal/value.
===== Example =====
{{:alvis:example5.png|}}
agent A {
loop {
delay 10;
select {
alt (ready [out(a)] { out a; }
alt (ready [out(b)] { out b; }
}
}
}
agent B {
...
In the above example, the ''A'' agent sends a signal through either the ''a'' or the ''b'' port depending on the requests of agents ''B'' and ''C''. If both port are ready, the ''a'' port is chosen.