comp.lang.ada
 help / color / mirror / Atom feed
From: Anh Vo <anhvofrcaus@gmail.com>
Subject: Re: Freezing a task
Date: Fri, 18 Nov 2011 14:25:17 -0800 (PST)
Date: 2011-11-18T14:25:17-08:00	[thread overview]
Message-ID: <cfdf14ce-1304-4c52-a8ec-3cfbd51669ee@g21g2000yqc.googlegroups.com> (raw)
In-Reply-To: ja517h$1ajm$1@news.ett.com.ua

On Nov 17, 11:24 pm, a...@att.net wrote:
> --
> --  Complete Program
> --
>
> with Text_IO ;
>
> procedure u is
>
>   use Text_IO ;
>
>   task type test is
>       entry Start ;    -- initialize and start task
>                        -- and task can die if parent stops
>
>       entry Wait ;     -- Send task to sleep for a while
>                        -- and task can die if parent stops
>
>       entry Continue ; -- wake up task
>       entry Stop ;     -- stops and kill task
>   end test ;
>
>   task body test is
>
>       Count : Integer ;
>     begin
>       --  Initialize task
>       Count := 0  ;
>       Outer_Loop : loop
>         select
>           --  start task
>           accept Start ;
>             Put_Line ( "Start" ) ;
>
>             Main_Loop : loop
>               select
>
>                 --  pause task
>                 accept Wait ;
>                   Put_Line ( "Wait" ) ;
>                   New_Line ;
>
>                   select
>
>                     --  sofware wake up task
>                     accept Continue ;
>                       Put_Line ( "Continue" ) ;
>
>                   --  software exit while in wait mode
>                   or
>                     accept Stop ;
>                       Put_Line ( "Stop" ) ;
>                       exit Outer_Loop ;
>
>                   --  exit if parent fails while in wait mode
>                   or
>                     terminate ;
>                   end select ;
>
>               --  software exit (abort) while in normal
>               --  execution mode
>               or
>                 accept Stop ;
>                     Put_Line ( "Stop" ) ;
>                     exit Outer_Loop ;
>
>               else
>                 -- - - - - - - - - - - --
>                 --  Main Tasking Code  --
>                 -- - - - - - - - - - - --
>                 Put ( "Testing" ) ;
>                 Put ( Integer'Image ( Count ) ) ;
>                 New_Line ;
>                 Count := Count + 1 ;
>               end select ;
>           end loop Main_Loop ;
>
>         --  exit if parent fails
>         or
>           terminate ;
>         end select ;
>       end loop Outer_Loop ;
>       Put_Line ( "Task has Terminated" ) ;
>     end test ;
>
>  testing_task      : test ;
>
> begin
>   Put_Line ( "Start Tasking" ) ;
>   New_Line ;
>   --
>   testing_task.Start ;
>   delay ( 0.01 ) ;
>   testing_task.Wait ;
>   delay ( 1.0 ) ;
>   testing_task.Continue ;
>   delay ( 0.01 ) ;
>   testing_task.Wait ;
>   --
>   delay ( 1.0 ) ;
>   testing_task.Stop ;
>   delay ( 0.5 ) ;
>   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-18 22:25 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 [this message]
2011-11-19  7:37     ` anon
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