comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Running a background task
Date: Thu, 15 May 2008 15:31:42 -0700 (PDT)
Date: 2008-05-15T15:31:42-07:00	[thread overview]
Message-ID: <760f4092-577e-440e-9fef-fb3ff3389560@h1g2000prh.googlegroups.com> (raw)
In-Reply-To: f47b5be0-7488-439e-903a-d16cbd4116f2@z24g2000prf.googlegroups.com

On May 15, 1:51 pm, Bender <Jeffrey.S.Morri...@gmail.com> wrote:
> Hi, I'm pretty new to Ada, and need to figure out a way to kick off a
> background task that runs more or less forever, while normal execution
> of the program continues.
>
> Thus far I've figured out how to create a task and start it, but the
> procedure calling it requires the task to finish before continuing
> on.  I'm sure I just must be using the wrong mechanisms, but I can't
> really figure out the answer.

When Handle_Msg calls on the On_String entry, this starts a
rendezvous, and Handle_Msg stops when the rendezvous is done.  Since
the "accept" has a "do" part, the rendezvous will not be done until
the "do" completes, which in your case never happens.  Thus,
Handle_Msg will never proceed past the entry call.

It's hard for me to give a solution, since I don't know just what
you're trying to accomplish; but you may want to move the loop out of
the "accept".

                                 -- Adam


> Task definition
> ---------------------
> (spec)
> task type Poll_For_Status is
>   entry On_String (String : in SideAB)
> end Poll_For_Status;
>
> type Task_Access is access Poll_For_Status;
> Status_Task : Task_Access;
>
> (body)
>   task body Poll_For_Status is
>   begin
>     accept On_String (String : in SideAB) do
>       loop
>         delay 3.0
>         Send_Status_Req (String);
>       end loop;
>     end On_String;
>   end Poll_For_Status;
>
> Calling procedure
> ------------------------
> procedure Handle_Msg(...) is
>   String : SideAB;
>   ...
> begin
> ...
>   Status_Task := new Poll_For_Status
>   Status_Task.On_String (String);
> ...
>
> If I remove the loop in the task body, it works fine.  Putting it in
> seems to halt execution.
>
> Am I missing anything?




  reply	other threads:[~2008-05-15 22:31 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 [this message]
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
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