comp.lang.ada
 help / color / mirror / Atom feed
From: Bender <Jeffrey.S.Morrison@gmail.com>
Subject: Re: Running a background task
Date: Thu, 15 May 2008 17:49:38 -0700 (PDT)
Date: 2008-05-15T17:49:38-07:00	[thread overview]
Message-ID: <a296dff1-13bf-4591-b399-ae68dd88f780@u6g2000prc.googlegroups.com> (raw)
In-Reply-To: 9n4Xj.111458$TT4.6745@attbi_s22

On May 15, 6:16 pm, "Jeffrey R. Carter"
<spam.jrcarter....@spam.acm.org> wrote:
> 1. You're missing the terminator semicolon.

Ignore that.  Just remnants of me hastily retyping my code in here.
It all compiles fine.

> 2. It's generally not a good idea to reuse the identifier "String", since it
> hides the predefined type String, which will cause confusing error msgs if you
> ever try to use that type.

Got it.

> You have no need for the access type. You can simply say
>
> Status_Task : Poll_For_Status;
>
> Status_Task won't do anything, since it waits for a call to On_String.
>
> You can simplify this even more by saying
>
> task Status_Task is
>     entry On_String (...);
> end Status_Task;
>
> This assumes that Status_Task is the only instance of Poll_For_Status.

I believe I originally did it this way, but then changed to using the
access stuff because it wasn't behaving the way I wanted it to.  I
thought using the new operator would hold the key to Handle_Msg not
caring about whether the task had finished yet or not, but it didn't.

> This infinite loop is inside the accept for On_String, which means the task that
> calls On_String will be blocked indefinitely.

That's my question in a nutshell.  I need the task to run forever.  I
need the Handle_Msg procedure to end and start handling other incoming
messages.

> 1. Having the task store the value passed to it:
>
>     Side : Sideab;
> begin -- Poll_For_Status;
>     accept On_String (String : in Sideab) do
>        Side := String;
>     end On_String;
>
>     loop
>        ...

Will this solve my problem?  Unfortunately I'm at home at the moment,
but once I get into work I'll give it a shot.  Once the 'end
On_String' is reached, will Handle_Msg continue on, while the task
continues to run?

> 2. Communicating via a protected object rather than a rendezvous. This is a
> bigger change, but depending on your needs might result in a better design.

This is such a simple task that I think what's above should be simple
enough to handle it, but I'll read up on it if necessary.

> It may not be important to you, but your loop does not execute every 3 seconds.
> There may be some time after the delay expires before the task starts executing
> again, and using "delay" allows those times to accumulate; there's also the time
> to call the subprogram. If you want it to be as close to every 3 seconds as you
> can get, you should use the "delay until" statement.

Yeah, I had read something about this before.  I'll look into it.

Thanks for all your help.



  reply	other threads:[~2008-05-16  0:49 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-15 20:51 Running a background task Bender
2008-05-15 22:31 ` Adam Beneschan
2008-05-15 23:14   ` Adam Beneschan
2008-05-16  0:43   ` Bender
2008-05-16 15:25     ` Adam Beneschan
2008-05-16 15:29       ` Adam Beneschan
2008-05-16  0:16 ` Jeffrey R. Carter
2008-05-16  0:49   ` Bender [this message]
2008-05-16  4:32     ` Jeffrey R. Carter
2008-05-16 14:34       ` Bender
replies disabled

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