[Home] [Prev] [Next] [Index]

9.7 Select Statements

9.7 Select Statements

1
There are three forms of select statements. One form provides a selective wait for one or more alternatives. The other two provide conditional and timed entry calls.

2
select_statement ::= selective_wait
      | conditional_entry_call | timed_entry_call

3
References:

*
selective wait 9.7.1

*
conditional entry call 9.7.2

*
timed entry call 9.7.3

9.7.1 Selective Waits

1
This form of the select statement allows a combination of waiting for, and selecting from, one or more alternatives. The selection can depend on conditions associated with each alternative of the selective wait.

2
selective_wait ::=
      select
                  select_alternative
      {or
                  select_alternative}
      [else
                  sequence_of_statements]
      end select;

select_alternative ::=
      [when condition =>]
            selective_wait_alternative

selective_wait_alternative ::= accept_alternative
      | delay_alternative | terminate_alternative

accept_alternative ::= accept_statement [sequence_of_statements]

delay_alternative ::= delay_statement [sequence_of_statements]

terminate_alternative ::= terminate;

3
A selective wait must contain at least one accept alternative. In addition a selective wait can contain either a terminate alternative (only one), or one or more delay alternatives, or an else part; these three possibilities are mutually exclusive.

4
A select alternative is said to be open if it does not start with when and a condition, or if the condition is TRUE. It is said to be closed otherwise.

5
For the execution of a selective wait, any conditions specified after when are evaluated in some order that is not defined by the language; open alternatives are thus determined. For an open delay alternative, the delay expression is also evaluated. Similarly, for an open accept alternative for an entry of a family, the entry index is also evaluated. Selection and execution of one open alternative, or of the else part, then completes the execution of the selective wait; the rules for this selection are described below.

6
Open accept alternatives are first considered. Selection of one such alternative takes place immediately if a corresponding rendezvous is possible, that is, if there is a corresponding entry call issued by another task and waiting to be accepted. If several alternatives can thus be selected, one of them is selected arbitrarily (that is, the language does not define which one). When such an alternative is selected, the corresponding accept statement and possible subsequent statements are executed. If no rendezvous is immediately possible and there is no else part, the task waits until an open selective wait alternative can be selected.

7
Selection of the other forms of alternative or of an else part is performed as follows:

8 ·
An open delay alternative will be selected if no accept alternative can be selected before the specified delay has elapsed (immediately, for a negative or zero delay in the absence of queued entry calls); any subsequent statements of the alternative are then executed. If several delay alternatives can thus be selected (that is, if they have the same delay), one of them is selected arbitrarily.

9 ·
The else part is selected and its statements are executed if no accept alternative can be immediately selected, in particular, if all alternatives are closed.

10 ·
An open terminate alternative is selected if the conditions stated in section 9.4 are satisfied. It is a consequence of other rules that a terminate alternative cannot be selected while there is a queued entry call for any entry of the task.

11
The exception PROGRAM_ERROR is raised if all alternatives are closed and there is no else part.

12
Examples of a select statement:

select
      accept DRIVER_AWAKE_SIGNAL;
or
      delay 30.0*SECONDS;
      STOP_THE_TRAIN;
end select;

13
Example of a task body with a select statement:

task body RESOURCE is
      BUSY : BOOLEAN := FALSE;
begin
      loop
            select
                  when not BUSY =>
                        accept SEIZE do
                              BUSY := TRUE;
                        end;
            or
                  accept RELEASE do
                        BUSY := FALSE;
                  end;
            or
                  terminate;
            end select;
      end loop;
end RESOURCE;

Notes:

14
A selective wait is allowed to have several open delay alternatives. A selective wait is allowed to have several open accept alternatives for the same entry.

15
References:

*
accept statement 9.5

*
condition 5.3

*
declaration 3.1

*
delay expression 9.6

*
delay statement 9.6

*
duration 9.6

*
entry 9.5

*
entry call 9.5

*
entry index 9.5

*
program_error exception 11.1

*
queued entry call 9.5

*
rendezvous 9.5

*
select statement 9.7

*
sequence of statements 5.1

*
task 9

9.7.2 Conditional Entry Calls

1
A conditional entry call issues an entry call that is then canceled if a rendezvous is not immediately possible.

2
conditional_entry_call ::=
      select
            entry_call_statement
            [sequence_of_statements]
      else
            sequence_of_statements
      end select;

3
For the execution of a conditional entry call, the entry name is first evaluated. This is followed by any evaluations required for actual parameters as in the case of a subprogram call (see 6.4).

4
The entry call is canceled if the execution of the called task has not reached a point where it is ready to accept the call (that is, either an accept statement for the corresponding entry, or a select statement with an open accept alternative for the entry), or if there are prior queued entry calls for this entry. If the called task has reached a select statement, the entry call is canceled if an accept alternative for this entry is not selected.

5
If the entry call is canceled, the statements of the else part are executed. Otherwise, the rendezvous takes place; and the optional sequence of statements after the entry call is then executed.

6
The execution of a conditional entry call raises the exception TASKING_ERROR if the called task has already completed its execution (see also 9.10 for the case when the called task becomes abnormal).

7
Example:

procedure SPIN(R : RESOURCE) is
begin
      loop
            select
                  R.SEIZE;
                  return;
            else
                  null; -- busy waiting
            end select;
      end loop;
end;

8
References:

*
abnormal task 9.10

*
accept statement 9.5

*
actual parameter part 6.4

*
completed task 9.4

*
entry call statement 9.5

*
entry family 9.5

*
entry index 9.5

*
evaluation 4.5

*
expression 4.4

*
open alternative 9.7.1

*
queued entry call 9.5

*
rendezvous 9.5

*
select statement 9.7

*
sequence of statements 5.1

*
task 9

*
tasking_error exception 11.1

9.7.3 Timed Entry Calls

1
A timed entry call issues an entry call that is canceled if a rendezvous is not started within a given delay.

2
timed_entry_call ::=
      select
            entry_call_statement
            [sequence_of_statements]
     or
            delay_alternative
      end select;

3
For the execution of a timed entry call, the entry name is first evaluated. This is followed by any evaluations required for actual parameters as in the case of a subprogram call (see 6.4). The expression stating the delay is then evaluated, and the entry call is finally issued.

4
If a rendezvous can be started within the specified duration (or immediately, as for a conditional entry call, for a negative or zero delay), it is performed and the optional sequence of statements after the entry call is then executed. Otherwise, the entry call is canceled when the specified duration has expired, and the optional sequence of statements of the delay alternative is executed.

5
The execution of a timed entry call raises the exception TASKING_ERROR if the called task completes its execution before accepting the call (see also 9.10 for the case when the called task becomes abnormal).

6
Example:

select
      CONTROLLER.REQUEST(MEDIUM)(SOME_ITEM);
or
      delay 45.0;
      -- controller too busy, try something else
end select;

7
References:

*
abnormal task 9.10

*
accept statement 9.5

*
actual parameter part 6.4

*
completed task 9.4

*
conditional entry call 9.7.2

*
delay expression 9.6

*
delay statement 9.6

*
duration 9.6

*
entry call statement 9.5

*
entry family 9.5

*
entry index 9.5

*
evaluation 4.5

*
expression 4.4

*
rendezvous 9.5

*
sequence of statements 5.1

*
task 9

*
tasking_error exception 11.1



[Home] [Prev] [Next] [Index]

documentation@rational.com
Copyright © 1993-2000, Rational Software Corporation. All rights reserved.