From: Jeffrey Carter <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: Freezing a task
Date: Thu, 17 Nov 2011 23:04:54 -0700
Date: 2011-11-17T23:04:54-07:00 [thread overview]
Message-ID: <ja4sl7$a7o$1@tornado.tornevall.net> (raw)
In-Reply-To: <32201299.75.1321579435782.JavaMail.geo-discussion-forums@yqbl36>
On 11/17/2011 06:23 PM, Rego, P. wrote:
>
> So I can use
>
> Paused : Boolean := False;
> begin
> accept Start;
> loop
> if Paused then
> accept Release;
> Paused := False;
> else
> select
> accept Pause;
> Paused := True;
> else
> ... -- Do stuff
> end select;
> end if;
> end loop;
>
> and if I would want to add an abort entry? What should I do?
Depends on when you want to be able to stop the task. I'd guess
select
accept Pause;
Paused := True;
or
accept Stop;
exit;
else
-- Do stuff.
end select;
"abort" is a reserved word, so it can't be the name of the entry. A protected
object seems cleaner, though:
protected Control is
procedure Process;
-- Instruct the task to start processing, or to resume processing after
-- being paused.
procedure Stop;
-- Tell the task to terminate.
procedure Pause;
-- Tell the task to pause processing.
entry Get (Stop : out Boolean);
-- Used by the task to wait until it should do something.
-- Stop will be True if the task should terminate; False if it should
-- do stuff.
private -- Control
...
end Control;
task body T is
Stop : Boolean;
begin -- T
loop
Control.Get (Stop => Stop);
exit when Stop;
-- Do stuff.
end loop;
end T;
--
Jeff Carter
"You can never forget too much about C++."
115
next prev parent reply other threads:[~2011-11-18 6:04 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 [this message]
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.
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox