comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Initializing an array of tasks with discrimants
Date: Sat, 23 Nov 2019 09:29:38 +0100
Date: 2019-11-23T09:29:38+01:00	[thread overview]
Message-ID: <qraqlj$41u$1@gioia.aioe.org> (raw)
In-Reply-To: 358a3934-7cb2-4cff-8703-71410815f27e@googlegroups.com

On 2019-11-22 23:07, Jere wrote:
> I recently ran into a situation where I had an array
> of tasks that had discriminants (with a default), but
> I couldn't find a simple way to initialize them.  I
> did come up with a workaround, but wanted to see if
> the language defined a way to do this:
> 
>      task type T(D: Integer := 3);

The cleanest way would be a protected generator of unique task IDs:

    protected ID is
       procedure Get (ID : out Integer);
    private
       Free : Integer := 0;
    end ID;

       procedure Get (ID : out Integer) is
       begin
           ID := Free;
           Free := Free + 1;
       end Get;

    task body T is
       D : Integer;
    begin
       ID.Get (D);
       ...
    end T;

No discriminants.

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


  parent reply	other threads:[~2019-11-23  8:29 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-22 22:07 Initializing an array of tasks with discrimants Jere
2019-11-22 22:39 ` Jeffrey R. Carter
2019-11-23 16:23   ` Jere
2019-11-22 23:57 ` Robert A Duff
2019-11-23  0:27   ` Anh Vo
2019-11-23  9:12   ` Randy Brukardt
2019-11-23 16:50     ` Jere
2019-11-23 16:25   ` Jere
2019-11-23  8:29 ` Dmitry A. Kazakov [this message]
2019-11-23 16:28   ` Jere
2019-11-23 17:03     ` Dmitry A. Kazakov
2019-11-23 16:57 ` Jere
2019-11-25 22:36   ` Randy Brukardt
replies disabled

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