-
An asynchronous select_statement provides asynchronous transfer of
control upon completion of an entry call or the expiration of a delay.
Syntax
-
asynchronous_select ::=
select
triggering_alternative
then abort
abortable_part
end select;
-
triggering_alternative ::=
triggering_statement [sequence_of_statements]
-
triggering_statement ::= entry_call_statement | delay_statement
-
abortable_part ::= sequence_of_statements
Dynamic Semantics
-
For the execution of an asynchronous_select whose triggering_statement
is an entry_call_statement, the entry_name and actual parameters are
evaluated as for a simple entry call, See section 9.5.3 Entry Calls, and the entry call
is issued. If the entry call is queued (or requeued-with-abort), then
the abortable_part is executed. If the entry call is selected
immediately, and never requeued-with-abort, then the abortable_part is
never started.
-
For the execution of an asynchronous_select whose triggering_statement
is a delay_statement, the delay_expression is evaluated and the
expiration time is determined, as for a normal delay_statement. If the
expiration time has not already passed, the abortable_part is executed.
-
If the abortable_part completes and is left prior to completion of the
triggering_statement, an attempt to cancel the triggering_statement is
made. If the attempt to cancel succeeds, See section 9.5.3 Entry Calls, and See section 9.6 Delay Statements, Duration, and Time,
the asynchronous_select is complete.
-
If the triggering_statement completes other than due to cancellation,
the abortable_part is aborted (if started but not yet completed --
See section 9.8 Abort of a Task - Abort of a Sequence of Statements.). If the triggering_statement completes normally, the
optional sequence_of_statements of the triggering_alternative is
executed after the abortable_part is left.
Examples
-
Example of a main command loop for a command interpreter:
-
loop
select
Terminal.Wait_For_Interrupt;
Put_Line("Interrupted");
then abort
-- This will be abandoned upon terminal interrupt
Put_Line("-> ");
Get_Line(Command, Last);
Process_Command(Command(1..Last));
end select;
end loop;
-
Example of a time-limited calculation:
-
select
delay 5.0;
Put_Line("Calculation does not converge");
then abort
-- This calculation should finish in 5.0 seconds;
-- if not, it is assumed to diverge.
Horribly_Complicated_Recursive_Function(X, Y);
end select;