comp.lang.ada
 help / color / mirror / Atom feed
From: anon@att.net
Subject: Re: Freezing a task
Date: Sat, 19 Nov 2011 07:37:26 +0000 (UTC)
Date: 2011-11-19T07:37:26+00:00	[thread overview]
Message-ID: <ja7mbk$tof$1@speranza.aioe.org> (raw)
In-Reply-To: cfdf14ce-1304-4c52-a8ec-3cfbd51669ee@g21g2000yqc.googlegroups.com

In some programming circles, the "main procedure" is also called the parent. 

And tasks without the "Terminate" statement some times will continue to 
execute, even when the parent aka "main procedure" dies. One reason for 
the disliked "Abort" statement.

Two examples of tasks that do not contain "terminate" statement are 
servers and tasking device drivers. For the task to stop, these tasks 
must be setup to handle a "Stop" type of call to interrupt the process 
or another routine may have to use the "Abort" statement.

Of course, there always the "Ada.Synchronous_Task_Control but that's
a more involved process. And a fully functional version of the package 
Ada.Asynchronous_Task_Control is not supply in the general release 
of GNAT version of Ada.

In my example the one thing I did not include was the single to 
multiple layers of exceptions that could be added.




In <cfdf14ce-1304-4c52-a8ec-3cfbd51669ee@g21g2000yqc.googlegroups.com>, Anh Vo <anhvofrcaus@gmail.com> writes:
>On Nov 17, 11:24=A0pm, a...@att.net wrote:
>> --
>> -- =A0Complete Program
>> --
>>
>> with Text_IO ;
>>
>> procedure u is
>>
>> =A0 use Text_IO ;
>>
>> =A0 task type test is
>> =A0 =A0 =A0 entry Start ; =A0 =A0-- initialize and start task
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0-- and task can die if par=
>ent stops
>>
>> =A0 =A0 =A0 entry Wait ; =A0 =A0 -- Send task to sleep for a while
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0-- and task can die if par=
>ent stops
>>
>> =A0 =A0 =A0 entry Continue ; -- wake up task
>> =A0 =A0 =A0 entry Stop ; =A0 =A0 -- stops and kill task
>> =A0 end test ;
>>
>> =A0 task body test is
>>
>> =A0 =A0 =A0 Count : Integer ;
>> =A0 =A0 begin
>> =A0 =A0 =A0 -- =A0Initialize task
>> =A0 =A0 =A0 Count :=3D 0 =A0;
>> =A0 =A0 =A0 Outer_Loop : loop
>> =A0 =A0 =A0 =A0 select
>> =A0 =A0 =A0 =A0 =A0 -- =A0start task
>> =A0 =A0 =A0 =A0 =A0 accept Start ;
>> =A0 =A0 =A0 =A0 =A0 =A0 Put_Line ( "Start" ) ;
>>
>> =A0 =A0 =A0 =A0 =A0 =A0 Main_Loop : loop
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 select
>>
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 -- =A0pause task
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 accept Wait ;
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Put_Line ( "Wait" ) ;
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 New_Line ;
>>
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 select
>>
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 -- =A0sofware wake up task
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 accept Continue ;
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Put_Line ( "Continue" ) ;
>>
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 -- =A0software exit while in wait mod=
>e
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 or
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 accept Stop ;
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Put_Line ( "Stop" ) ;
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 exit Outer_Loop ;
>>
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 -- =A0exit if parent fails while in w=
>ait mode
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 or
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 terminate ;
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 end select ;
>>
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 -- =A0software exit (abort) while in normal
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 -- =A0execution mode
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 or
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 accept Stop ;
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Put_Line ( "Stop" ) ;
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 exit Outer_Loop ;
>>
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 else
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 -- - - - - - - - - - - --
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 -- =A0Main Tasking Code =A0--
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 -- - - - - - - - - - - --
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Put ( "Testing" ) ;
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Put ( Integer'Image ( Count ) ) ;
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 New_Line ;
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Count :=3D Count + 1 ;
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 end select ;
>> =A0 =A0 =A0 =A0 =A0 end loop Main_Loop ;
>>
>> =A0 =A0 =A0 =A0 -- =A0exit if parent fails
>> =A0 =A0 =A0 =A0 or
>> =A0 =A0 =A0 =A0 =A0 terminate ;
>> =A0 =A0 =A0 =A0 end select ;
>> =A0 =A0 =A0 end loop Outer_Loop ;
>> =A0 =A0 =A0 Put_Line ( "Task has Terminated" ) ;
>> =A0 =A0 end test ;
>>
>> =A0testing_task =A0 =A0 =A0: test ;
>>
>> begin
>> =A0 Put_Line ( "Start Tasking" ) ;
>> =A0 New_Line ;
>> =A0 --
>> =A0 testing_task.Start ;
>> =A0 delay ( 0.01 ) ;
>> =A0 testing_task.Wait ;
>> =A0 delay ( 1.0 ) ;
>> =A0 testing_task.Continue ;
>> =A0 delay ( 0.01 ) ;
>> =A0 testing_task.Wait ;
>> =A0 --
>> =A0 delay ( 1.0 ) ;
>> =A0 testing_task.Stop ;
>> =A0 delay ( 0.5 ) ;
>> =A0 New_Line ;
>> end u ;
>
>I am not sure what was meant by couple of annotated comments
>mentioning parent fails. Normally, tasks are declared at library
>level. Thus, they will terminate when the main program terminates. In
>this particular example, the task will terminate when the main
>procedure terminates.
>
>Anh Vo




  reply	other threads:[~2011-11-19  7:37 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-17 15:33 Freezing a task Rego, P.
2011-11-17 16:00 ` Simon Wright
2011-11-17 16:22   ` Dmitry A. Kazakov
2011-11-17 16:53     ` Dmitry A. Kazakov
2011-11-17 18:27     ` Simon Wright
2011-11-18  1:23     ` Rego, P.
2011-11-18  6:04       ` Jeffrey Carter
2011-11-18  8:47       ` Dmitry A. Kazakov
2011-11-18 10:05         ` Simon Wright
2011-11-18 11:41           ` Georg Bauhaus
2011-11-18 13:42             ` Dmitry A. Kazakov
2011-11-17 16:00 ` Dmitry A. Kazakov
2011-11-17 16:53   ` stefan-lucks
2011-11-17 17:08     ` Dmitry A. Kazakov
2011-11-17 17:13 ` Adam Beneschan
2011-11-17 18:01   ` AdaMagica
2011-11-18  1:22   ` Rego, P.
2011-11-17 17:34 ` Jeffrey Carter
2011-11-18  1:34   ` Rego, P.
2011-11-18  8:56     ` Dmitry A. Kazakov
2011-11-18  7:24 ` anon
2011-11-18 22:25   ` Anh Vo
2011-11-19  7:37     ` anon [this message]
2011-11-22  1:58   ` Rego, P.
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox