comp.lang.ada
 help / color / mirror / Atom feed
From: Jeffrey Carter <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: dynamic vs static tasks allocation
Date: Thu, 16 Oct 2014 11:45:34 -0700
Date: 2014-10-16T11:45:34-07:00	[thread overview]
Message-ID: <m1p3ob$ed5$2@dont-email.me> (raw)
In-Reply-To: <a4e161b4-f966-4c40-80b9-6dfe760815da@googlegroups.com>

On 10/16/2014 10:25 AM, Stribor40 wrote:
> If you know ahead of time how many tasks will be needed is it better to
> create tasks dynamically with new operator or just statically?
> 
> Which is way is recommended and why even bother allocating dynamically?

There are actually 3 ways to create tasks:

1. Statically, in a pkg or the main procedure:

package body P is
   task Foo is

2. Dynamically without access types, using block statements or subprograms:

task type Foo;

type Foo_List is array (Positive range <>) of Foo;

procedure P (Num_Workers : in Positive) is
   Worker : Foo_List (1 .. N);

3. Dynamically with access types, using new:

task type Foo;
type Foo_Ptr is access Foo;

Worker : Foo_Ptr;
...
Worker := new Foo;

1 and 2 are often both considered static allocation.

The trouble with 3, as with any use of access types, is memory management. With
access-to-task types, you also have to be sure the task has terminated before
freeing it. For these reasons, I avoid 3 whenever possible.

-- 
Jeff Carter
"I blow my nose on you."
Monty Python & the Holy Grail
03

  parent reply	other threads:[~2014-10-16 18:45 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-16 17:25 dynamic vs static tasks allocation Stribor40
2014-10-16 18:18 ` mockturtle
2014-10-16 18:41   ` Adam Beneschan
2014-10-16 18:45 ` Jeffrey Carter [this message]
2014-10-17  0:07 ` Dennis Lee Bieber
replies disabled

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