comp.lang.ada
 help / color / mirror / Atom feed
* Freezing a task
@ 2011-11-17 15:33 Rego, P.
  2011-11-17 16:00 ` Simon Wright
                   ` (4 more replies)
  0 siblings, 5 replies; 24+ messages in thread
From: Rego, P. @ 2011-11-17 15:33 UTC (permalink / raw)


Is is possible to freeze a task?

I mean, if I have a task

task body My_Task is
begin 
  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 instance, the execution finished executing Put ("2");, how can I freeze it and later I can turn it to continue? I want to provoque a freeze from outside 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 
  accept Start;
  loop
    Put ("1");
    Put ("2");
    Put ("3");
    ...
    Put ("n");

    loop 
     if State = 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 instruction line (i.e., the task would not be actually frozen, because the inside loop 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 
   entry Start;
   entry Run;
end My_Task
--
task body My_Task is
begin 
  accept Start;
  loop
    Put ("1");
    Put ("2");
    Put ("3");
    ...
    Put ("n");

    if State = FROZEN then 
       accept Run;
       State := RUN;
    end if;
  end loop;
end My_Task;

Is there a more elegant way to do this? Maybe some procedure My_Task.FreezeNow in a unknown (by me) package? Thanks



^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2011-11-22  1:58 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2011-11-22  1:58   ` Rego, P.

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