comp.lang.ada
 help / color / mirror / Atom feed
From: Niklas Holsti <niklas.holsti@tidorum.invalid>
Subject: Re: dynamically create tasks
Date: Sat, 11 Oct 2014 08:53:31 +0300
Date: 2014-10-11T08:53:31+03:00	[thread overview]
Message-ID: <c9ruu7F88njU1@mid.individual.net> (raw)
In-Reply-To: <47e42c27-69ba-44fc-861f-c230f5ac04f4@googlegroups.com>

On 14-10-11 04:49 , compguy45@gmail.com wrote:
> If you have one task body and would like to create 5 of these
> tasks since there is one task body there will only be one task
> created plus main task....how would you create 20 tasks with same body?
> is there way to do this?
> 

Use task types. Instead of saying

   task My_Own_Task is
   ...
   end My_Own_Task;

say

   task type My_Own_Task is
   ...
   end My_Own_Task;

The "task body" part stays the same. Then you can create as many tasks
as you like, of this type, using what looks like a normal variable
declaration:

   Thinker, Doer, Builder, Painter : My_Own_Task;

and now all these tasks are running. You can also create arrays of tasks
in the normal way, " ... array ( ... ) of My_Own_Task", you can have
access types for tasks and use "new My_Own_Task", and so on.

(However, I would suffix task-type names with "_T", just as I do for
other types, so I would write My_Own_Task_T for the task-type name.)

Note that when you use a task type and have several tasks with the same
body, there must be some way for each task to know what *it* should do;
all tasks should of course not do exactly the same thing. One way is to
add an entry to each task and call these entries to give different
parameters to each task; another way is for each task to call some
central task or protected object to get their different parameters. You
can also give the task type discriminants that tell each task what to
do; that may be useful if you create tasks dynamically (wth "new").

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
      .      @       .


  parent reply	other threads:[~2014-10-11  5:53 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-11  1:49 dynamically create tasks compguy45
2014-10-11  2:20 ` Shark8
2014-10-11  5:53 ` Niklas Holsti [this message]
2014-10-11 13:02   ` compguy45
2014-10-11 14:51     ` Dmitry A. Kazakov
2014-10-11 16:34       ` compguy45
2014-10-11 17:29         ` Ludovic Brenta
2014-10-11 18:52         ` Brad Moore
2014-10-11  6:01 ` Simon Wright
replies disabled

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