From: "Karen" <karen.nussbaum@blueyonder.co.uk>
Subject: Re: Task discriminants
Date: Mon, 07 Jun 2004 22:12:29 GMT
Date: 2004-06-07T22:12:29+00:00 [thread overview]
Message-ID: <hL5xc.555$_p4.4918544@news-text.cableinet.net> (raw)
In-Reply-To: 2iceofFlgn4pU1@uni-berlin.de
Or the obvious approach, to declare a access type to the task type. Then
have an array of those access types, which are initialised using different
discriminants as you need.
(from a posting newbie, but an Ada Graybeard)
ian(dot)nussbaum(at)blueyonder.co.uk
"Nick Roberts" <nick.roberts@acm.org> wrote in message
news:2iceofFlgn4pU1@uni-berlin.de...
> "Dave Levy" <dlevy@mail.usyd.edu.au> wrote in message
> news:40ACC50E.9040406@mail.usyd.edu.au...
>
> > Suppose one has a task type with a discriminant:
> >
> > task type A_Task( Id : integer);
> >
> > and one wishes to declare a set of tasks with initialised discriminants:
> > t1 : A_Task(1);
> > t2 : A_Task(2);
> > t3 : A_Task(3);
> >
> > How could one declare them as an array of tasks with each one getting an
> > initialised discriminant? Perhaps something like:
> >
> > The_Tasks: array (1..3) of A_Task( Id => 1,2,3 );
> >
> > Except I tried this with Gnat and it won't compile.
>
> It is a basic precept of Ada arrays that its components are all of the
same
> subtype. This means that they cannot have different discriminants. So this
> approach, as such, is doomed.
>
> You could use the 'old' technique:
>
> type A_Task_Number is range 1..3;
>
> task type A_Task is
> entry Init (Num: in A_Task_Number);
> ...
> end;
>
> The_Tasks: array (A_Task_Number) of A_Task;
>
> ...
> for i in A_Task_Number loop
> The_Tasks(i).Init(i);
> end loop;
> ...
>
> task body A_Task is
> My_Num: A_Task_Number;
> ...
> begin
> accept Init (Num: in A_Task_Number) do
> My_Num := Num;
> end;
> ...
> end A_Task;
>
> It's always worked for me!
>
> --
> Nick Roberts
>
>
prev parent reply other threads:[~2004-06-07 22:12 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-05-20 14:47 Task discriminants Dave Levy
2004-05-20 17:17 ` David C. Hoos
2004-05-20 18:37 ` Martin Dowie
2004-05-21 0:39 ` Georg Bauhaus
2004-05-21 1:04 ` Jeffrey Carter
2004-05-21 9:43 ` Phil Slater
2004-05-21 12:43 ` Martin Dowie
2004-05-21 19:42 ` Randy Brukardt
2004-05-21 22:05 ` Martin Dowie
[not found] ` <c8luk4$29b$1@hercules.btinternet.com>
2004-05-21 23:16 ` Randy Brukardt
2004-05-22 7:55 ` Martin Dowie
2004-05-24 21:34 ` Randy Brukardt
2004-05-25 5:48 ` Martin Dowie
2004-05-25 20:25 ` Randy Brukardt
2004-05-25 22:40 ` Martin Dowie
2004-05-20 17:30 ` Martin Krischik
2004-05-21 7:57 ` Dmitry A. Kazakov
2004-06-04 12:59 ` Andersen Jacob Sparre
2004-05-21 16:46 ` Robert I. Eachus
2004-05-22 7:54 ` Martin Dowie
2004-05-22 16:18 ` Pascal Obry
2004-05-24 21:36 ` Randy Brukardt
2004-05-25 21:22 ` Robert I. Eachus
2004-06-04 23:26 ` Nick Roberts
2004-06-07 22:12 ` Karen [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox