Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Both sides next revision
alvis:out [2015/11/24 21:35]
marcin
— (current)
Line 1: Line 1:
-====== Out statement ====== 
  
-An agent can communicate with its outside world using **ports**. Each port can be used both as an input or an output one. The current role of a port is determined by two factors: 
-  - Connections to the port in the corresponding communication diagram -- e.g. if a port ''p'' is used only as an input port for an one-way connection, it cannot be used as an output port. 
-  - Statements used in the code layer -- e.g. if a port ''p'' is used only as an argument of the **in** statement, it is an input port even if all its connections are two-way ones. 
- 
-Any communication through a port can be a **pure communication** or a **value passing combination**.  
- 
-In case of a **pure communication**, the **out** statement sends a signal (without specified value) through the statement port. 
- 
-In case of a **value passing communication**, the **out** statement sends a value of the statement parameter (or a literal) through the statement port. 
- 
-The **out** statement as a **blocking communication** is a single-step statement.  
- 
-<code> 
-out p; 
-out p x; 
-out p v; 
-</code> 
- 
-**Listing 1. ** In statement syntax: ''p'' stands for a port name, ''x'' stands for a parameter name and ''v'' stands for a literal value. 
- 
- 
-** Example 1 ** 
- 
-{{:alvis:example3.png|}} 
- 
-**Figure 1. ** Example 1 communication diagram 
- 
-<code> 
-agent A { 
-  out a; 
-} 
- 
-agent B { 
-  in b; 
-} 
-</code> 
- 
-**Listing 2. ** Example 1 code layer 
- 
-The only task of agent ''A'' is sending a signal through its port ''a'' and the only task of agent ''B'' is collecting a signal through its port ''b'' 
- 
-A communication between two active agents can be initialised by any of them. The agent that initialises it, performs the **out** statement to provide some information and waits for the second agent to take it, or performs the **in** statement to express its readiness to collect some information and waits until the second agent provides it. 
- 
-**Example 2** 
- 
-{{:alvis:example4.png|}} 
- 
-**Figure 2. ** Example 2 communication diagram 
- 
-<code> 
-agent A { 
-  out a; 
-} 
- 
-agent B { 
-  in b; 
-} 
- 
-agent C { 
-  in c; 
-} 
-</code> 
- 
-**Listing 3. ** Example 2 code layer 
- 
-In the above example the port ''A.a'' is connected with two other ports, but only one of them will collect the signal. If both agents ''B'' and ''C'' are waiting for the signal, the choice between them is indeterministic. To avoid indeterminism, different priorities for these agents should be assigned. 
- 
-A **blocking communication** means that if an agent initialises a communication with the **out** statement then it waits until another agent finishes it. The communication cannot be aborted.  
- 
-A communication with a passive agent denotes a procedure call. If an agent initialises a communication with the **out** statement and the corresponding procedure is accessible, then the passive agent starts executing it. Otherwise, the active agent waits for the procedure accessibility.  
- 
-The **out** statement as an **non-blocking communication** may be a single-step or multi-step statement.  
- 
-<code> 
-out (0) p x {  
-  success { ... } 
-  fail    { ... } 
-} 
- 
-out (0) p x {            
-  fail    { ... } 
-} 
- 
-out (0) p x {            
-  success { ... } 
-} 
- 
-out (0) p x; 
- 
-out (0) p {  
-  success { ... } 
-  fail    { ... } 
-} 
- 
-out (0) p {            
-  fail    { ... } 
-} 
- 
-out (0) p {            
-  success { ... } 
-} 
- 
-out (0) p; 
-</code> 
- 
-**Listing 4. ** Out statement syntax (non-blocking version): ''p'' stands for a port name and ''x'' stands for a parameter name. Instead a parameter name, a literal value can be used. 
- 
-A **non-blocking communication** means that the agent aborts the communication if it cannot be realized immediately. The statement may contain optional **success** and **fail** clauses. The former is executed after successful realization of a communication. The latter is executed if the communication has been aborted.  
- 
-If an agent communicates with an active agent then a **non-blocking out** succeeds if it finishes the communication.  
- 
-If an agent calls a procedure of a passive agent then a **non-blocking out** succeeds if the procedure is accessible and starts immediately. 
- 
- 
- 
-**See also:** [[:alvis:in|In statement]], [[:alvis:proc|Proc statement]]. 
- 
-**[[:alvis:manual|Go back]]**