This is an old revision of the document!


Proc statement

Passive agents are used to store data shared among agents and to avoid the simultaneous use of such data by two or more agents. They provide a set of procedures that can be called by other agents. Each procedure has its own port attached and a communication with a passive agent via that port is treated as the corresponding procedure call. Depending on the communication direction, such a procedure may be used to send or collect some data from the passive agent.

proc (g) p {...}

Listing 1. Proc statement syntax, where g stands for a guard and is optional and p stands for the corresponding port name.

A procedure is accessible for other agents only if the guard evaluates to True.

A communication between an active and a passive agent (a procedure call) can be initialised only by the former. Any procedure in Alvis uses only one either input or output parameter (or signal in case of parameterless communication). In case of an input procedure, an active agent calls the procedure using the out statement (and provides the parameter, if any, at the same time). If the corresponding passive agent is in the waiting mode and the procedure is accessible, the agent starts it in the active agent context. The passive agent collects the signal/parameter using the in statement, but it is not necessary to put the statement as the first procedure step. Similarly, in case of an output procedure, an active agent calls the procedure using the in statement. The passive agent returns the result using the out statement, but it is not necessary to put the statement as the last procedure step.

Example

This is a part of a model only!

agent Buffer {
  i :: Int = 0;
  proc pop  { out pop i; }
  proc push { in  push i; }
}

Go back