4 -- Grant of Unlimited Rights
6 -- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
7 -- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained
8 -- unlimited rights in the software and documentation contained herein.
9 -- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making
10 -- this public release, the Government intends to confer upon all
11 -- recipients unlimited rights equal to those held by the Government.
12 -- These rights include rights to use, duplicate, release or disclose the
13 -- released technical data and computer software in whole or in part, in
14 -- any manner and for any purpose whatsoever, and to have or permit others
19 -- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
20 -- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
21 -- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
22 -- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
23 -- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
24 -- PARTICULAR PURPOSE OF SAID MATERIAL.
28 -- Check that the abortable part of an asynchronous select statement
29 -- is aborted if it does not complete before the triggering statement
30 -- completes, where the triggering statement is a delay_relative
31 -- statement and check that the sequence of statements of the triggering
32 -- alternative is executed after the abortable part is left.
35 -- Declare a task with an accept statement containing an asynchronous
36 -- select with a delay_relative triggering statement. Parameterize
37 -- the accept statement with the time to be used in the delay. Simulate a
38 -- time-consuming calculation by declaring a procedure containing an
39 -- infinite loop. Call this procedure in the abortable part.
41 -- The delay will expire before the abortable part completes, at which
42 -- time the abortable part is aborted, and the sequence of statements
43 -- following the triggering statement is executed.
47 -- 06 Dec 94 SAIC ACVC 2.0
57 --========================================================--
59 -- Medium length delay
60 Allotted_Time
: constant Duration := ImpDef
.Switch_To_New_Task
;
62 Calculation_Canceled
: exception;
65 Count
: Integer := 1234;
67 procedure Lengthy_Calculation
is
69 -- Simulate a non-converging calculation.
70 loop -- Infinite loop.
71 Count
:= (Count
+ 1) mod 10;
72 delay ImpDef
.Minimum_Task_Switch
; -- allow other task
74 end Lengthy_Calculation
;
77 --========================================================--
80 task type Timed_Calculation
is
81 entry Calculation
(Time_Limit
: in Duration);
82 end Timed_Calculation
;
85 task body Timed_Calculation
is
90 accept Calculation
(Time_Limit
: in Duration) do
93 -- Asynchronous select is tested here --
97 delay Time_Limit
; -- Time_Limit is not up yet, so
98 -- Lengthy_Calculation starts.
100 raise Calculation_Canceled
; -- This is executed after
101 -- Lengthy_Calculation aborted.
103 Lengthy_Calculation
; -- Delay expires before complete,
104 -- so this call is aborted.
106 -- Check that the whole of the abortable part is aborted,
107 -- not just the statement in the abortable part that was
108 -- executing at the time
109 Report
.Failed
("Abortable part not aborted");
113 Report
.Failed
("Triggering alternative sequence of " &
114 "statements not executed");
116 exception -- New Ada 9x: handler within accept
117 when Calculation_Canceled
=>
119 Report
.Failed
("Abortable part did not execute");
128 Report
.Failed
("Unexpected exception in Timed_Calculation task");
129 end Timed_Calculation
;
132 --========================================================--
135 begin -- Main program.
137 Report
.Test
("C974001", "Asynchronous Select: Trigger is delay_relative" &
138 " which completes before abortable part");
141 Timed
: Timed_Calculation
; -- Task.
143 Timed
.Calculation
(Time_Limit
=> Allotted_Time
); -- Asynchronous select
144 -- inside accept block.
146 when Calculation_Canceled
=>
147 null; -- expected behavior