comp.lang.ada
 help / color / mirror / Atom feed
From: anon@att.net
Subject: Re: Freezing a task
Date: Fri, 18 Nov 2011 07:24:35 +0000 (UTC)
Date: 2011-11-18T07:24:35+00:00	[thread overview]
Message-ID: <ja517h$1ajm$1@news.ett.com.ua> (raw)
In-Reply-To: 32992849.648.1321544004241.JavaMail.geo-discussion-forums@vbmh5

--
--  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 ;


In <32992849.648.1321544004241.JavaMail.geo-discussion-forums@vbmh5>, "Rego, P." <pvrego@gmail.com> writes:
>Is is possible to freeze a task?
>
>I mean, if I have a task
>
>task body My_Task is
>begin=20
>  accept Start;
>  loop
>    Put ("1");
>    Put ("2");
>    Put ("3");
>    ...
>    Put ("n");
>  end loop;
>end My_Task;
>
>is there a way that I can "freeze" the task in its current state? If, for i=
>nstance, the execution finished executing Put ("2");, how can I freeze it a=
>nd later I can turn it to continue? I want to provoque a freeze from outsid=
>e the task, and also from outside, order it to continue.
>
>I could sure implement, if I had the spec like
>
>type State_Type is
>  (RUN,
>   FROZEN);
>
>task type My_Task (State : State_Type) is
>   entry Start;
>end My_Task;
>--
>
>the body:
>
>task body My_Task is
>begin=20
>  accept Start;
>  loop
>    Put ("1");
>    Put ("2");
>    Put ("3");
>    ...
>    Put ("n");
>
>    loop=20
>     if State =3D RUN then exit; end if;
>    end loop;
>  end loop;
>end My_Task;
>
>but it would not be the case because I had to wait for the nth Put instruct=
>ion line (i.e., the task would not be actually frozen, because the inside l=
>oop would be running).
>
>And T.E.D. from stackoverflow suggested me something that I could infer as
>
>task type My_Task (Start : Start_Type) is=20
>   entry Start;
>   entry Run;
>end My_Task
>--
>task body My_Task is
>begin=20
>  accept Start;
>  loop
>    Put ("1");
>    Put ("2");
>    Put ("3");
>    ...
>    Put ("n");
>
>    if State =3D FROZEN then=20
>       accept Run;
>       State :=3D RUN;
>    end if;
>  end loop;
>end My_Task;
>
>Is there a more elegant way to do this? Maybe some procedure My_Task.Freeze=
>Now in a unknown (by me) package? Thanks




  parent reply	other threads:[~2011-11-18  7:24 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 [this message]
2011-11-18 22:25   ` Anh Vo
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