From: Adam Beneschan <adam@irvine.com>
Subject: Re: Freezing a task
Date: Thu, 17 Nov 2011 09:13:53 -0800 (PST)
Date: 2011-11-17T09:13:53-08:00 [thread overview]
Message-ID: <ac0ddb7b-f6c1-47f6-8318-6e4ea6c50aa9@g27g2000pre.googlegroups.com> (raw)
In-Reply-To: 32992849.648.1321544004241.JavaMail.geo-discussion-forums@vbmh5
On Nov 17, 7:33 am, "Rego, P." <pvr...@gmail.com> wrote:
> 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
Aside from the other suggestions, you might want to look into
Ada.Synchronous_Task_Control and Ada.Asynchronous_Task_Control. I'm
not really clear on what you're trying to accomplish, so it's hard for
me to say whether those are appropriate solutions for you. I think
that the other methods that have been suggested--an entry call on
another task or on a protected object, or an ACCEPT statement--would
be preferable if they get the job done.
-- Adam
next prev parent reply other threads:[~2011-11-17 17:20 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 [this message]
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.
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox