help / color / mirror / Atom feed
From: Niklas Holsti <niklas.holsti@tidorum.invalid>
Subject: Re: Arrays with discriminated task components
Date: Sun, 25 Dec 2022 18:16:56 +0200	[thread overview]
Message-ID: <> (raw)
In-Reply-To: <>

On 2022-12-24 13:44, AdaMagica wrote:
> I've got a task type with a discriminant:
> type Index is range 1 .. N;
> task type T (D: Index);
> Now I want an array of these tasks, where each task knows its 
> identity  (the index) via the discriminant, an iterated_component_association:
> Arr: array (Index) of T := (for I in Index => ???);
> How can I do this?
> This works with access, but I find this extremely ugly:
> Arr: array (Index) of access T := (for I in Index => new T (I));
> Alternatively, I could use the traditional method with a Start entry with the index as parameter:
> task type T is
>    entry Start (D: Index);
> end T;

This seems to work with gnat, but I'm not entirely sure if it is legal 
(could there be a conflict between the default value of the task 
discriminant, which is the same for all tasks in the array, and the 
actual discriminants which are different for each task in the array?):

    N : constant := 10;

    type Index is range 1 .. N;

    task type T (D: Index := Index'First);
    -- A default value for D is needed to make the type constrained, as
    -- required by the Arr declaration below.

    function New_T (I : in Index)
    return T
       return TI : T (D => I)
       end return;
    end New_T;

    Arr: array (Index) of T := (for I in Index => New_T(I));

Whether this is any less ugly than the heap allocation method is doubtful.

  parent reply	other threads:[~2022-12-25 16:16 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-24 11:44 Arrays with discriminated task components AdaMagica
2022-12-24 18:05 ` Niklas Holsti
2022-12-24 22:41   ` Jeffrey R.Carter
2022-12-25 15:32     ` Niklas Holsti
2022-12-25 16:16 ` Niklas Holsti [this message]
2022-12-26 16:39   ` AdaMagica
replies disabled

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