comp.lang.ada
 help / color / mirror / Atom feed
* Tasks reinitializing
@ 2009-09-17 18:21 Pablo
  2009-09-17 21:42 ` Adam Beneschan
  2009-09-18  7:57 ` Dmitry A. Kazakov
  0 siblings, 2 replies; 5+ messages in thread
From: Pablo @ 2009-09-17 18:21 UTC (permalink / raw)


How can I reinitialize a task?
Say us, I have two cases:
A task defined as
   task type Task_type is
      entry Start;
   end Task_type;
so the object defined as
Init : Init_type;

and inside a procedure, the task is initialized with
accept Start;

and now:
1) In run time, the task is terminated by aborting process (abort
Init) before its end, and in the same session, I need to turn it on
again, but now from the beginning.
2) In run time, the task is finished by very end, and in the same
session, I need to start it again from beginning.

Please help me!



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

* Re: Tasks reinitializing
  2009-09-17 18:21 Tasks reinitializing Pablo
@ 2009-09-17 21:42 ` Adam Beneschan
  2009-09-17 22:39   ` Anh Vo
  2009-09-18  7:57 ` Dmitry A. Kazakov
  1 sibling, 1 reply; 5+ messages in thread
From: Adam Beneschan @ 2009-09-17 21:42 UTC (permalink / raw)


On Sep 17, 11:21 am, Pablo <pablit...@gmail.com> wrote:
> How can I reinitialize a task?
> Say us, I have two cases:
> A task defined as
>    task type Task_type is
>       entry Start;
>    end Task_type;
> so the object defined as
> Init : Init_type;

You mean Init : Task_Type, I presume??

> and inside a procedure, the task is initialized with
> accept Start;
>
> and now:
> 1) In run time, the task is terminated by aborting process (abort
> Init) before its end, and in the same session, I need to turn it on
> again, but now from the beginning.
> 2) In run time, the task is finished by very end, and in the same
> session, I need to start it again from beginning.
>
> Please help me!

You'll need to create a new task object.  If you declare an object

   Init : Task_Type;

and it's declared as a local variable inside a procedure Proc1, the
only way it's going to get reinitialized is if Proc1 exits and starts
up again.  If Init is declared in a library package, then it's never
going to happen.

You may want to try using an access:

   type Task_Type_Acc is access Task_Type;

   Init : Task_Type_Acc := new Task_Type;

When you allocate a new Task_Type with "new", that will start a task
up.  If, after the task finishes, you want to start a new one, you can
assign

   Init := new Task_Type;

at any point, and it will start a new task.  I think that's probably
what you want.

                                       -- Adam



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

* Re: Tasks reinitializing
  2009-09-17 21:42 ` Adam Beneschan
@ 2009-09-17 22:39   ` Anh Vo
  2009-09-18  5:44     ` sjw
  0 siblings, 1 reply; 5+ messages in thread
From: Anh Vo @ 2009-09-17 22:39 UTC (permalink / raw)


On Sep 17, 2:42 pm, Adam Beneschan <a...@irvine.com> wrote:
> On Sep 17, 11:21 am, Pablo <pablit...@gmail.com> wrote:
>
> > How can I reinitialize a task?
> > Say us, I have two cases:
> > A task defined as
> >    task type Task_type is
> >       entry Start;
> >    end Task_type;
> > so the object defined as
> > Init : Init_type;
>
> You mean Init : Task_Type, I presume??
>
> > and inside a procedure, the task is initialized with
> > accept Start;
>
> > and now:
> > 1) In run time, the task is terminated by aborting process (abort
> > Init) before its end, and in the same session, I need to turn it on
> > again, but now from the beginning.
> > 2) In run time, the task is finished by very end, and in the same
> > session, I need to start it again from beginning.
>
> > Please help me!
>
> You'll need to create a new task object.  If you declare an object
>
>    Init : Task_Type;
>
> and it's declared as a local variable inside a procedure Proc1, the
> only way it's going to get reinitialized is if Proc1 exits and starts
> up again.  If Init is declared in a library package, then it's never
> going to happen.
>
> You may want to try using an access:
>
>    type Task_Type_Acc is access Task_Type;
>
>    Init : Task_Type_Acc := new Task_Type;
>
> When you allocate a new Task_Type with "new", that will start a task
> up.  If, after the task finishes, you want to start a new one, you can
> assign
>
>    Init := new Task_Type;
>
> at any point, and it will start a new task.  I think that's probably
> what you want.

Just to make it complete, I would recommend deallocating memory,
before starting a new task, to prevent memory leaks.

Anh Vo




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

* Re: Tasks reinitializing
  2009-09-17 22:39   ` Anh Vo
@ 2009-09-18  5:44     ` sjw
  0 siblings, 0 replies; 5+ messages in thread
From: sjw @ 2009-09-18  5:44 UTC (permalink / raw)


On Sep 17, 11:39 pm, Anh Vo <anhvofrc...@gmail.com> wrote:
> On Sep 17, 2:42 pm, Adam Beneschan <a...@irvine.com> wrote:

> > You may want to try using an access:
>
> >    type Task_Type_Acc is access Task_Type;
>
> >    Init : Task_Type_Acc := new Task_Type;
>
> > When you allocate a new Task_Type with "new", that will start a task
> > up.  If, after the task finishes, you want to start a new one, you can
> > assign
>
> >    Init := new Task_Type;
>
> > at any point, and it will start a new task.  I think that's probably
> > what you want.
>
> Just to make it complete, I would recommend deallocating memory,
> before starting a new task, to prevent memory leaks.

Yes, but you need to be careful here.

If you say

   abort Init.all;
   Free (Init);

then (at least with GNAT, at least on VxWorks, unless they've changed
recently) you may free the task stack but not the task control block.

   abort Init.all;
   while not Init.all'Terminated loop
      delay 0.001;
   end loop;
   Free (Init);

You might want to figure out a way to delegate the loop and the free
to a lower-priority task.



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

* Re: Tasks reinitializing
  2009-09-17 18:21 Tasks reinitializing Pablo
  2009-09-17 21:42 ` Adam Beneschan
@ 2009-09-18  7:57 ` Dmitry A. Kazakov
  1 sibling, 0 replies; 5+ messages in thread
From: Dmitry A. Kazakov @ 2009-09-18  7:57 UTC (permalink / raw)


On Thu, 17 Sep 2009 11:21:41 -0700 (PDT), Pablo wrote:

> How can I reinitialize a task?
> Say us, I have two cases:
> A task defined as
>    task type Task_type is
>       entry Start;
>    end Task_type;
> so the object defined as
> Init : Init_type;
> 
> and inside a procedure, the task is initialized with
> accept Start;
> 
> and now:
> 1) In run time, the task is terminated by aborting process (abort
> Init) before its end, and in the same session, I need to turn it on
> again, but now from the beginning.

If the process is aborted, all its tasks are dead. You probably mean
aborting the task. Then just do not abort it if you steel need it.

> 2) In run time, the task is finished by very end, and in the same
> session, I need to start it again from beginning.

task body Task_type is
begin
   loop
      select
         accept Start; -- Wait for a session to start
         ... -- Do what has to be done in this session
      or terminate; -- Complete when no more needed
      end select;
   end loop;
end Task_type;

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



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

end of thread, other threads:[~2009-09-18  7:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-17 18:21 Tasks reinitializing Pablo
2009-09-17 21:42 ` Adam Beneschan
2009-09-17 22:39   ` Anh Vo
2009-09-18  5:44     ` sjw
2009-09-18  7:57 ` Dmitry A. Kazakov

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