comp.lang.ada
 help / color / mirror / Atom feed
From: Stephen Leake <stephen.a.leake.1@gsfc.nasa.gov>
Subject: Re: Multiple task bodies for one task type?
Date: 17 Sep 2001 10:15:13 -0400
Date: 2001-09-17T14:16:30+00:00	[thread overview]
Message-ID: <u7kuxgaz2.fsf@gsfc.nasa.gov> (raw)
In-Reply-To: 3BA2A012.1C2A2903@san.rr.com

Darren New <dnew@san.rr.com> writes:

> What's the normal Ada idiom for having multiple types of task in an
> array?

There is no direct support for arrays of heterogeneous objects in Ada.
You can have arrays of tagged types, and the concrete types can have
different task objects:

type base_type is abstract tagged null record;
type base_access_type is access all base_type'class;

type task_1_tagged_type is new base_type with record
    task_1 : task_1_type;
end record;

type task_2_tagged_type is new base_type with record
    task_2 : task_2_type;
end record;

type task_array_type is array (1 .. 10) of base_access_type;
 
> Basically, I want a bunch of tasks where I can do something like
> 
> tat : array (1..10) of mumble;
> ta : tat;
> begin
>   -- "perform" is an entry or a protected procedure
>   ta(1).perform(30);
>   ta(2).perform(30);
> end
> 
> and have the two calls execute different code.

You can use task discriminants to execute different code (I forget the
syntax, so I won't give an example).

> Generally, I want to write a framework where these tasks act
> something like callbacks, except I expect I'm going to want them to
> actually be tasks and protected objects (probably one of each).

You can use real callbacks; pass a subprogram pointer to each task in
an Initialize rendezvous.

> But it looks like each task type gets exactly one task body.

Yes, but it can be parameterized by task attributes, or the entries
can be parameterized by family parameters (again, I forget the syntax).

> Of course, the primary problem is that things like "accept" and
> "abort" and such have to actually be in the task body itself, not in
> subprograms called from the task body, or I'd just make (say) a
> generic with a procedure for each entry, or something.
> 
> Any hints how one would go about this? Thanks in advance!

Try writing a detailed example in illegal Ada that shows what you
want, then we can help make it legal.

-- 
-- Stephe



      parent reply	other threads:[~2001-09-17 14:15 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-09-15  0:26 Multiple task bodies for one task type? Darren New
2001-09-17  9:37 ` John McCabe
2001-09-17 14:01   ` Tucker Taft
2001-09-18 19:01   ` Richard Riehle
2001-09-18 21:03     ` Darren New
2001-09-18 21:26     ` tmoran
2001-09-17 14:15 ` Stephen Leake [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