From: Shark8 <onewingedshark@gmail.com>
Subject: Tasking troubles, unexpected termination.
Date: Tue, 30 Oct 2012 15:03:44 -0700 (PDT)
Date: 2012-10-30T15:03:44-07:00 [thread overview]
Message-ID: <53dff738-0847-43ea-bd4c-51b0cd30816f@googlegroups.com> (raw)
with
Ada.Text_IO,
Ada.Calendar,
Ada.Containers.Indefinite_Vectors;
Procedure Scheduling is
-- Introduce shorthand so convert Strings to access strings.
Function "+" (Item : String) Return Not Null Access String is
( New String'(Item) );
-- Forward declare the Notification type; indicate it has discriminants.
Type Notification(<>);
-- Declare Handle for Notifications.
Type Notification_Handle is Not Null Access Notification;
Type Notification( Message : Not Null Access String;
Expiry : Not Null Access Ada.Calendar.Time
) is null record;
-- Declare the Timing-task.
Task Type Timing ( Resolution : Not Null Access Duration ) is
Entry Add( Event : Notification_Handle );
end Timing;
-- Implementation for the timing-task.
Task body Timing is
-- Internal package, defining Vectors holding notification handles.
Package Notification_Vector is New Ada.Containers.Indefinite_Vectors
( Index_Type => Positive, Element_Type => Notification_Handle );
Use Notification_Vector;
-- Declare a Vector to hold all the notifications.
Notification_List : Vector:= Empty_Vector;
Procedure Handle_Expiration is
Use Ada.Calendar, Ada.Text_IO;
Length : Positive:= Positive(Notification_List.Length);
Now : Time:= Clock;
begin
-- Iterate through the vector's elements; reversed so that deletion
-- does not intefere with the iteration.
for Index in reverse 1..Length loop
declare
Item : Notification_Handle Renames Notification_List(Index);
begin
-- If it's reached the expiry, then we display the message
-- and remove the item.
if Now > Item.Expiry.All then
Put_Line( "Message: " & Item.Message.All);
Notification_List.Delete(Index);
end if;
end;
end loop;
declare
Post_op_length : Positive:= Positive(Notification_List.Length);
begin
if Length /= post_op_length then
Put_Line( "Deleted items; New Length:" & post_op_length'Img);
end if;
end;
end Handle_Expiration;
Use Ada.Containers;
begin
-- When there are no items in our internal vector, then we need can only
-- accept Add or terminate the task.
-- When we add an item, then we can either add another item or when the
-- time expires iterate the vector and handling Notifications as needed.
loop
select
accept Add( Event : Notification_Handle ) do
Notification_List.Append( Event );
end add;
while not Notification_List.Is_Empty loop
Handle_Expiration;
select
accept Add( Event : Notification_Handle ) do
Notification_List.Append( Event );
Ada.Text_IO.Put_Line( "New Length: " & Notification_List.Length'Img );
end add;
or
delay Timing.Resolution.All;
end select;
end loop;
Ada.Text_IO.Put_Line( "EMPTY. Length: " & Notification_List.Length'Img );
or
terminate;
end select;
end loop;
end Timing;
K : Timing( Resolution => New Duration'(2.0) );
begin
For Index in 1..10 loop
declare
Use Ada.Calendar;
Expire : Time:= Clock + (Index*2.0); -- Now and 2*Index seconds.
Item : Notification(
Message => + ("DD"&Positive'Image(Index)),
Expiry => New Time'( Expire )
);
begin
K.Add( Event => New Notification'(Item) );
end;
end loop;
end Scheduling;
----------------------------------
Output:
C:\Programming\Projects\Scheduler>scheduling.exe
New Length: 2
New Length: 3
New Length: 4
New Length: 5
New Length: 6
New Length: 7
New Length: 8
New Length: 9
New Length: 10
Message: DD 10
As you can see there's something happening to force termination -- there should at the least be an new-length message -- this leads me to believe [or, more accurately, guess] that there's some exception happening in the task which is blowing everything up.
Is that the case?
Also, if there is some tasking-exceptions interaction, how do I force them to display [and/or handle them] instead of falling off a cliff?
next reply other threads:[~2012-10-30 22:03 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-30 22:03 Shark8 [this message]
2012-10-30 23:01 ` Tasking troubles, unexpected termination Adam Beneschan
2012-10-31 1:05 ` Anh Vo
2012-10-31 2:17 ` Shark8
2012-10-31 2:59 ` Shark8
2012-11-02 16:02 ` Anh Vo
2012-11-01 9:39 ` AdaMagica
2012-11-02 1:18 ` Shark8
2012-11-02 16:43 ` Adam Beneschan
2012-11-02 16:51 ` Shark8
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox