comp.lang.ada
 help / color / mirror / Atom feed
* Generic Formal Parameter for a Task Type
@ 2001-03-08 22:38 James Rogers
  2001-03-08 23:27 ` Marin David Condic
                   ` (2 more replies)
  0 siblings, 3 replies; 18+ messages in thread
From: James Rogers @ 2001-03-08 22:38 UTC (permalink / raw)


I have looked through "Ada as a Second Language" and the Ada Reference
manual. I cannot find any proper form to pass a task type as a
generic formal parameter.

Is there a generic formal parameter form for this purpose?

I wanted to create a generic package I call Task_Governor. This
package would control the number of tasks one could create at once.
The idea is that task resources may be limited. This package would
allow someone to limit the number of tasks to a maximum specified.
An instantiation of the package would monitor the tasks it started
and allow another to be started when one of the tasks terminated.

My problem is that I cannot figure out how to specify a task type
as a generic formal parameter.

Any hints?

Jim Rogers
Colorado Springs, Colorado USA



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Generic Formal Parameter for a Task Type
  2001-03-08 22:38 Generic Formal Parameter for a Task Type James Rogers
@ 2001-03-08 23:27 ` Marin David Condic
  2001-03-09  0:00 ` Robert A Duff
  2001-03-09  0:16 ` Pat Rogers
  2 siblings, 0 replies; 18+ messages in thread
From: Marin David Condic @ 2001-03-08 23:27 UTC (permalink / raw)


Stop me if I'm wrong on this.... :-)

One possible solution would be to use a private type as the parameter and
pass a pointer to the task - or a record containing the pointer. I don't
think there is a mechanism to pass a task type as a generic formal. Perhaps
the designers anticipated the pointer mechanism I mention.

MDC

--
Marin David Condic
Senior Software Engineer
Pace Micro Technology Americas    www.pacemicro.com
Enabling the digital revolution
e-Mail:    marin.condic@pacemicro.com
Web:      http://www.mcondic.com/



"James Rogers" <jimmaureenrogers@worldnet.att.net> wrote in message
news:3AA80A68.A2C8B042@worldnet.att.net...
> I have looked through "Ada as a Second Language" and the Ada Reference
> manual. I cannot find any proper form to pass a task type as a
> generic formal parameter.
>
> Is there a generic formal parameter form for this purpose?
>
> I wanted to create a generic package I call Task_Governor. This
> package would control the number of tasks one could create at once.
> The idea is that task resources may be limited. This package would
> allow someone to limit the number of tasks to a maximum specified.
> An instantiation of the package would monitor the tasks it started
> and allow another to be started when one of the tasks terminated.
>
> My problem is that I cannot figure out how to specify a task type
> as a generic formal parameter.
>
> Any hints?
>
> Jim Rogers
> Colorado Springs, Colorado USA





^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Generic Formal Parameter for a Task Type
  2001-03-08 22:38 Generic Formal Parameter for a Task Type James Rogers
  2001-03-08 23:27 ` Marin David Condic
@ 2001-03-09  0:00 ` Robert A Duff
  2001-03-09  0:16 ` Pat Rogers
  2 siblings, 0 replies; 18+ messages in thread
From: Robert A Duff @ 2001-03-09  0:00 UTC (permalink / raw)


James Rogers <jimmaureenrogers@worldnet.att.net> writes:

> I have looked through "Ada as a Second Language" and the Ada Reference
> manual. I cannot find any proper form to pass a task type as a
> generic formal parameter.

Consider a formal limited private type, or a formal derived type.

- Bob



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Generic Formal Parameter for a Task Type
  2001-03-08 22:38 Generic Formal Parameter for a Task Type James Rogers
  2001-03-08 23:27 ` Marin David Condic
  2001-03-09  0:00 ` Robert A Duff
@ 2001-03-09  0:16 ` Pat Rogers
  2001-03-09  3:34   ` James Rogers
  2 siblings, 1 reply; 18+ messages in thread
From: Pat Rogers @ 2001-03-09  0:16 UTC (permalink / raw)



"James Rogers" <jimmaureenrogers@worldnet.att.net> wrote in message
news:3AA80A68.A2C8B042@worldnet.att.net...
> I have looked through "Ada as a Second Language" and the Ada Reference
> manual. I cannot find any proper form to pass a task type as a
> generic formal parameter.
>
> Is there a generic formal parameter form for this purpose?
>
> I wanted to create a generic package I call Task_Governor. This
> package would control the number of tasks one could create at once.
> The idea is that task resources may be limited. This package would
> allow someone to limit the number of tasks to a maximum specified.
> An instantiation of the package would monitor the tasks it started
> and allow another to be started when one of the tasks terminated.
>
> My problem is that I cannot figure out how to specify a task type
> as a generic formal parameter.

There is no generic formal task type; you have to use a limited private
formal.

---
Patrick Rogers                       Consulting and Training in:
http://www.classwide.com        Real-Time/OO Languages
progers@classwide.com          Hard Deadline Schedulability Analysis
(281)648-3165                          Software Fault Tolerance





^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Generic Formal Parameter for a Task Type
  2001-03-09  0:16 ` Pat Rogers
@ 2001-03-09  3:34   ` James Rogers
  2001-03-09  4:26     ` Pat Rogers
  2001-03-09 15:50     ` Stephen Leake
  0 siblings, 2 replies; 18+ messages in thread
From: James Rogers @ 2001-03-09  3:34 UTC (permalink / raw)


The problem with using a formal limited private type is in the
need to determine if one of the tasks being monitored has terminated.

The 'Terminated attribute only applies to Task objects, either
directly, or implicitly through an access to the task object.

A limited private type is too general. It is not viewed within the
generic as a task type. I know. I tried this first.

The only way to make such a system work is to creat a limited record
type containing an access to task type. You could then create a
function taking a parameter of the record type, returning the proper
response from the 'Terminated attribute.

Although this is easily done, it is not what I wanted. I had hoped
to be able to create a generic package directly usable with most
any task type.

This appears to be one problem not solvable in Ada, yet easily
solved in Java. 

I would like to add a generic task type formal parameter to the
list of improvements for the next version of Ada.

Jim Rogers
Colorado Springs, Colorado USA

Pat Rogers wrote:
> 
> "James Rogers" <jimmaureenrogers@worldnet.att.net> wrote in message
> news:3AA80A68.A2C8B042@worldnet.att.net...
> > I have looked through "Ada as a Second Language" and the Ada Reference
> > manual. I cannot find any proper form to pass a task type as a
> > generic formal parameter.
> >
> > Is there a generic formal parameter form for this purpose?
> >
> > I wanted to create a generic package I call Task_Governor. This
> > package would control the number of tasks one could create at once.
> > The idea is that task resources may be limited. This package would
> > allow someone to limit the number of tasks to a maximum specified.
> > An instantiation of the package would monitor the tasks it started
> > and allow another to be started when one of the tasks terminated.
> >
> > My problem is that I cannot figure out how to specify a task type
> > as a generic formal parameter.
> 
> There is no generic formal task type; you have to use a limited private
> formal.
> 
> ---
> Patrick Rogers                       Consulting and Training in:
> http://www.classwide.com        Real-Time/OO Languages
> progers@classwide.com          Hard Deadline Schedulability Analysis
> (281)648-3165                          Software Fault Tolerance



^ permalink raw reply	[flat|nested] 18+ messages in thread

* RE: Generic Formal Parameter for a Task Type
@ 2001-03-09  4:20 Beard, Frank
  2001-03-09  5:24 ` James Rogers
  0 siblings, 1 reply; 18+ messages in thread
From: Beard, Frank @ 2001-03-09  4:20 UTC (permalink / raw)
  To: 'comp.lang.ada@ada.eu.org'

Why can't you have something like the following:

   generic

      type Item is limited private;
      with function Terminated(the_Item : Item) return boolean;

   package Xyz is

      procedure Monitor(the_Item : Item);
      ...

   end Xyz;

You instantiate the package with the task type and supply the
Terminated function, which would look something like:

   function Terminated(the_Task : Task_Type) return boolean is
   begin
      return the_Task'terminated;
   end Terminated;

So, inside your generic where you are monitoring the task, you
call the supplied function.  Of course, you would have to supply
a function for every task attribute you wanted to check.  I know
it's not as clean as using the attribute directly, but it's not
that bad.

I haven't tried to test this but the spec part compiles and it
seems like it should work, but I might be missing something.

Frank

-----Original Message-----
From: James Rogers [mailto:jimmaureenrogers@worldnet.att.net]
Sent: Thursday, March 08, 2001 10:35 PM
To: comp.lang.ada@ada.eu.org
Subject: Re: Generic Formal Parameter for a Task Type


The problem with using a formal limited private type is in the
need to determine if one of the tasks being monitored has terminated.

The 'Terminated attribute only applies to Task objects, either
directly, or implicitly through an access to the task object.

A limited private type is too general. It is not viewed within the
generic as a task type. I know. I tried this first.

The only way to make such a system work is to creat a limited record
type containing an access to task type. You could then create a
function taking a parameter of the record type, returning the proper
response from the 'Terminated attribute.

Although this is easily done, it is not what I wanted. I had hoped
to be able to create a generic package directly usable with most
any task type.

This appears to be one problem not solvable in Ada, yet easily
solved in Java. 

I would like to add a generic task type formal parameter to the
list of improvements for the next version of Ada.

Jim Rogers
Colorado Springs, Colorado USA

Pat Rogers wrote:
> 
> "James Rogers" <jimmaureenrogers@worldnet.att.net> wrote in message
> news:3AA80A68.A2C8B042@worldnet.att.net...
> > I have looked through "Ada as a Second Language" and the Ada Reference
> > manual. I cannot find any proper form to pass a task type as a
> > generic formal parameter.
> >
> > Is there a generic formal parameter form for this purpose?
> >
> > I wanted to create a generic package I call Task_Governor. This
> > package would control the number of tasks one could create at once.
> > The idea is that task resources may be limited. This package would
> > allow someone to limit the number of tasks to a maximum specified.
> > An instantiation of the package would monitor the tasks it started
> > and allow another to be started when one of the tasks terminated.
> >
> > My problem is that I cannot figure out how to specify a task type
> > as a generic formal parameter.
> 
> There is no generic formal task type; you have to use a limited private
> formal.
> 
> ---
> Patrick Rogers                       Consulting and Training in:
> http://www.classwide.com        Real-Time/OO Languages
> progers@classwide.com          Hard Deadline Schedulability Analysis
> (281)648-3165                          Software Fault Tolerance
_______________________________________________
comp.lang.ada mailing list
comp.lang.ada@ada.eu.org
http://ada.eu.org/mailman/listinfo/comp.lang.ada




^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Generic Formal Parameter for a Task Type
  2001-03-09  3:34   ` James Rogers
@ 2001-03-09  4:26     ` Pat Rogers
  2001-03-09  4:58       ` James Rogers
  2001-03-09 15:50     ` Stephen Leake
  1 sibling, 1 reply; 18+ messages in thread
From: Pat Rogers @ 2001-03-09  4:26 UTC (permalink / raw)


See RM C.7.1 for package Ada.Task_Identification, specifically function
Is_Terminated.  That may be enough...



"James Rogers" <jimmaureenrogers@worldnet.att.net> wrote in message
news:3AA84FC7.CE523E9D@worldnet.att.net...
> The problem with using a formal limited private type is in the
> need to determine if one of the tasks being monitored has terminated.
>
> The 'Terminated attribute only applies to Task objects, either
> directly, or implicitly through an access to the task object.
>
> A limited private type is too general. It is not viewed within the
> generic as a task type. I know. I tried this first.
>
> The only way to make such a system work is to creat a limited record
> type containing an access to task type. You could then create a
> function taking a parameter of the record type, returning the proper
> response from the 'Terminated attribute.
>
> Although this is easily done, it is not what I wanted. I had hoped
> to be able to create a generic package directly usable with most
> any task type.
>
> This appears to be one problem not solvable in Ada, yet easily
> solved in Java.
>
> I would like to add a generic task type formal parameter to the
> list of improvements for the next version of Ada.
>
> Jim Rogers
> Colorado Springs, Colorado USA
>
> Pat Rogers wrote:
> >
> > "James Rogers" <jimmaureenrogers@worldnet.att.net> wrote in message
> > news:3AA80A68.A2C8B042@worldnet.att.net...
> > > I have looked through "Ada as a Second Language" and the Ada Reference
> > > manual. I cannot find any proper form to pass a task type as a
> > > generic formal parameter.
> > >
> > > Is there a generic formal parameter form for this purpose?
> > >
> > > I wanted to create a generic package I call Task_Governor. This
> > > package would control the number of tasks one could create at once.
> > > The idea is that task resources may be limited. This package would
> > > allow someone to limit the number of tasks to a maximum specified.
> > > An instantiation of the package would monitor the tasks it started
> > > and allow another to be started when one of the tasks terminated.
> > >
> > > My problem is that I cannot figure out how to specify a task type
> > > as a generic formal parameter.
> >
> > There is no generic formal task type; you have to use a limited private
> > formal.
> >
> > ---
> > Patrick Rogers                       Consulting and Training in:
> > http://www.classwide.com        Real-Time/OO Languages
> > progers@classwide.com          Hard Deadline Schedulability Analysis
> > (281)648-3165                          Software Fault Tolerance
>





^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Generic Formal Parameter for a Task Type
  2001-03-09  4:26     ` Pat Rogers
@ 2001-03-09  4:58       ` James Rogers
  0 siblings, 0 replies; 18+ messages in thread
From: James Rogers @ 2001-03-09  4:58 UTC (permalink / raw)




Pat Rogers wrote:
> 
> See RM C.7.1 for package Ada.Task_Identification, specifically function
> Is_Terminated.  That may be enough...
> 

According to RM C.7.1(5):
"A value of the type Task_ID identifies an existent task. The constant
Null_Task_Id does not identify and task. Each object of the type
Task_ID is default initialized to the value of Null_Task_Id."

This means that I would need to create the task object outside the
generic package. Inside the generic package I could not clearly
identify the limited private type as a task. It could not, therefore
have a Task_ID. My generic package cannot control the creation
of task objects outside its own scope. I must be able to create the
task object within the scope of the generic package.

The best I could do inside the generic package is create a number
of Task_ID objects, all with the default value of Null_Task_Id.

Jim Rogers
Colorado Springs, Colorado USA



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Generic Formal Parameter for a Task Type
  2001-03-09  4:20 Beard, Frank
@ 2001-03-09  5:24 ` James Rogers
  2001-03-09 21:50   ` Tucker Taft
  0 siblings, 1 reply; 18+ messages in thread
From: James Rogers @ 2001-03-09  5:24 UTC (permalink / raw)


"Beard, Frank" wrote:
> 
> Why can't you have something like the following:
> 
>    generic
> 
>       type Item is limited private;
>       with function Terminated(the_Item : Item) return boolean;
> 
>    package Xyz is
> 
>       procedure Monitor(the_Item : Item);
>       ...
> 
>    end Xyz;
> 
> You instantiate the package with the task type and supply the
> Terminated function, which would look something like:
> 
>    function Terminated(the_Task : Task_Type) return boolean is
>    begin
>       return the_Task'terminated;
>    end Terminated;
> 
> So, inside your generic where you are monitoring the task, you
> call the supplied function.  Of course, you would have to supply
> a function for every task attribute you wanted to check.  I know
> it's not as clean as using the attribute directly, but it's not
> that bad.
> 
> I haven't tried to test this but the spec part compiles and it
> seems like it should work, but I might be missing something.

Yep. That works. Thanks for the inspiration.

This is still a bit nastier than I hoped for. As you say, it requires
a function for each attribute. This gets even worse if someone 
employs the Ada.Task_Attributes package. This solution requires
a lot of explicit imfrastructure for the programmer. One can still
not simply pass a task type to a generic package, and let that
package directly deal with objects of that task type.

The package is still left ignorant of the fact it is dealing
with a task type.

I would still like to see Ada 20XY contain a generic formal
parameter type for task types and task access types.

Whining aside, I am pleased to have a solution, even if it is
an ugly one.

Jim Rogers
Colorado Springs, Colorado USA



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Generic Formal Parameter for a Task Type
  2001-03-09  3:34   ` James Rogers
  2001-03-09  4:26     ` Pat Rogers
@ 2001-03-09 15:50     ` Stephen Leake
  2001-03-10  3:15       ` James Rogers
  1 sibling, 1 reply; 18+ messages in thread
From: Stephen Leake @ 2001-03-09 15:50 UTC (permalink / raw)


James Rogers <jimmaureenrogers@worldnet.att.net> writes:

> <snip>
>
> 
> Although this is easily done, it is not what I wanted. I had hoped
> to be able to create a generic package directly usable with most any
> task type.
> 
> This appears to be one problem not solvable in Ada, yet easily
> solved in Java. 

Say what? Java has no notion of "generic package"! So what "problem"
are you solving in Java?

If you change the problem statement to "create a class that can manage
tasks that are all derived from a common Object type", then that is
easily done in Ada!

-- 
-- Stephe



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Generic Formal Parameter for a Task Type
  2001-03-09  5:24 ` James Rogers
@ 2001-03-09 21:50   ` Tucker Taft
  2001-03-10  0:14     ` Robert C. Leif, Ph.D.
  2001-03-10  3:25     ` James Rogers
  0 siblings, 2 replies; 18+ messages in thread
From: Tucker Taft @ 2001-03-09 21:50 UTC (permalink / raw)


James Rogers wrote:
> 
> "Beard, Frank" wrote:
> >
> > Why can't you have something like the following:
> >
> >    generic
> >
> >       type Item is limited private;
> >       with function Terminated(the_Item : Item) return boolean;
> >
> >    package Xyz is
> >
> >       procedure Monitor(the_Item : Item);
> >       ...
> >
> >    end Xyz;
> >
> > You instantiate the package with the task type and supply the
> > Terminated function, which would look something like:
> >
> >    function Terminated(the_Task : Task_Type) return boolean is
> >    begin
> >       return the_Task'terminated;
> >    end Terminated;
> >
> > So, inside your generic where you are monitoring the task, you
> > call the supplied function.  Of course, you would have to supply
> > a function for every task attribute you wanted to check.  I know
> > it's not as clean as using the attribute directly, but it's not
> > that bad.
> >
> > I haven't tried to test this but the spec part compiles and it
> > seems like it should work, but I might be missing something.
> 
> Yep. That works. Thanks for the inspiration.
> 
> This is still a bit nastier than I hoped for. As you say, it requires
> a function for each attribute. ...

Why not have a formal function that returns the Task_ID, rather
than 'Terminated?  That way, you can use the Ada.Task_Identification
and Ada.Task_Attributes packages to get whatever else you need from the
task, including task attributes...

If you wanted to avoid generics, you could define an abstract limited
tagged type (say "Has_Task") which had various (abstract) primitive 
operations, including  at least a "Task_ID" function.  You would then 
extend from this type by adding a component of the task type of interest
(and of course override the abstract primitives as appropriate).  
You could then manipulate objects of type Has_Task'Class, or references
there-to, in a "Java"-like way ;-).  You could also pass in any
extension of Has_Task to a generic with a formal tagged derived type
of "type My_Task is new Has_Task with private;".

The possibilities are endless...


> Jim Rogers
> Colorado Springs, Colorado USA

-- 
-Tucker Taft   stt@avercom.net   http://www.averstar.com/~stt/
Chief Technology Officer, AverCom Corporation (A Titan Company) 
Burlington, MA  USA (AverCom was formerly the Commercial Division of AverStar:
http://www.averstar.com/services/ebusiness_applications.html)



^ permalink raw reply	[flat|nested] 18+ messages in thread

* RE: Generic Formal Parameter for a Task Type
@ 2001-03-09 22:53 Beard, Frank
  0 siblings, 0 replies; 18+ messages in thread
From: Beard, Frank @ 2001-03-09 22:53 UTC (permalink / raw)
  To: 'comp.lang.ada@ada.eu.org'


-----Original Message-----
From: Tucker Taft [mailto:stt@averstar.com]

> Why not have a formal function that returns the Task_ID, rather
> than 'Terminated?  That way, you can use the Ada.Task_Identification
> and Ada.Task_Attributes packages to get whatever else you need from the
> task, including task attributes...

Good idea.  It didn't cross my mind. I still think too much in Ada 83 terms.

> If you wanted to avoid generics, you could define an abstract limited
> tagged type (say "Has_Task") which had various (abstract) primitive 
> operations, including  at least a "Task_ID" function.  You would then 
> extend from this type by adding a component of the task type of interest
> (and of course override the abstract primitives as appropriate).  
> You could then manipulate objects of type Has_Task'Class, or references
> there-to, in a "Java"-like way ;-).  You could also pass in any
> extension of Has_Task to a generic with a formal tagged derived type
> of "type My_Task is new Has_Task with private;".

Yeah!  Whatever you said.




^ permalink raw reply	[flat|nested] 18+ messages in thread

* RE: Generic Formal Parameter for a Task Type
  2001-03-09 21:50   ` Tucker Taft
@ 2001-03-10  0:14     ` Robert C. Leif, Ph.D.
  2001-03-12 16:14       ` Tucker Taft
  2001-03-10  3:25     ` James Rogers
  1 sibling, 1 reply; 18+ messages in thread
From: Robert C. Leif, Ph.D. @ 2001-03-10  0:14 UTC (permalink / raw)
  To: comp.lang.ada

From: Bob Leif
To: Tucker Taft et al.
You wrote:
"If you wanted to avoid generics, you could define an abstract limited
tagged type (say "Has_Task") which had various (abstract) primitive
operations, including  at least a "Task_ID" function.  You would then
extend from this type by adding a component of the task type of interest
(and of course override the abstract primitives as appropriate)."

Can you include the "Has_Task" in a generic package; or are the two
approaches mutually exclusive for tasks?

-----Original Message-----
From: comp.lang.ada-admin@ada.eu.org
[mailto:comp.lang.ada-admin@ada.eu.org]On Behalf Of Tucker Taft
Sent: Friday, March 09, 2001 1:51 PM
To: comp.lang.ada@ada.eu.org
Subject: Re: Generic Formal Parameter for a Task Type


James Rogers wrote:
>
> "Beard, Frank" wrote:
> >
> > Why can't you have something like the following:
> >
> >    generic
> >
> >       type Item is limited private;
> >       with function Terminated(the_Item : Item) return boolean;
> >
> >    package Xyz is
> >
> >       procedure Monitor(the_Item : Item);
> >       ...
> >
> >    end Xyz;
> >
> > You instantiate the package with the task type and supply the
> > Terminated function, which would look something like:
> >
> >    function Terminated(the_Task : Task_Type) return boolean is
> >    begin
> >       return the_Task'terminated;
> >    end Terminated;
> >
> > So, inside your generic where you are monitoring the task, you
> > call the supplied function.  Of course, you would have to supply
> > a function for every task attribute you wanted to check.  I know
> > it's not as clean as using the attribute directly, but it's not
> > that bad.
> >
> > I haven't tried to test this but the spec part compiles and it
> > seems like it should work, but I might be missing something.
>
> Yep. That works. Thanks for the inspiration.
>
> This is still a bit nastier than I hoped for. As you say, it requires
> a function for each attribute. ...

Why not have a formal function that returns the Task_ID, rather
than 'Terminated?  That way, you can use the Ada.Task_Identification
and Ada.Task_Attributes packages to get whatever else you need from the
task, including task attributes...

If you wanted to avoid generics, you could define an abstract limited
tagged type (say "Has_Task") which had various (abstract) primitive
operations, including  at least a "Task_ID" function.  You would then
extend from this type by adding a component of the task type of interest
(and of course override the abstract primitives as appropriate).
You could then manipulate objects of type Has_Task'Class, or references
there-to, in a "Java"-like way ;-).  You could also pass in any
extension of Has_Task to a generic with a formal tagged derived type
of "type My_Task is new Has_Task with private;".

The possibilities are endless...


> Jim Rogers
> Colorado Springs, Colorado USA

--
-Tucker Taft   stt@avercom.net   http://www.averstar.com/~stt/
Chief Technology Officer, AverCom Corporation (A Titan Company)
Burlington, MA  USA (AverCom was formerly the Commercial Division of
AverStar:
http://www.averstar.com/services/ebusiness_applications.html)





^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Generic Formal Parameter for a Task Type
  2001-03-09 15:50     ` Stephen Leake
@ 2001-03-10  3:15       ` James Rogers
  0 siblings, 0 replies; 18+ messages in thread
From: James Rogers @ 2001-03-10  3:15 UTC (permalink / raw)


I admit I misspoke about Java. I forgot the constructor problem in
Java.

My estimation of what is needed in Java is an extension of the Java
Thread Group to allow a limit to the number of threads the group
can contain. This is clearly a matter of inventing a new 
capability for Java, not simply a clever programming paradigm.

You are correct in stating that Java has no generic capabilities.
Java partly gets around it lack of generics because it has a common
inheritance structure. All Java thread classes inherit from the
class Thread. This means that a Java reference to a Thread 
object may reference any sublclass of Thread.

Ada tasks are not part of an inheritance structure.

It is possible to create a tagged type with one or more tasks
as members of the type. This is not the same thing, although it
can be used to partially simulate the Java situation.

Jim Rogers
Colorado Springs, Colorado USA

Stephen Leake wrote:
> 
> James Rogers <jimmaureenrogers@worldnet.att.net> writes:
> 
> > <snip>
> >
> >
> > Although this is easily done, it is not what I wanted. I had hoped
> > to be able to create a generic package directly usable with most any
> > task type.
> >
> > This appears to be one problem not solvable in Ada, yet easily
> > solved in Java.
> 
> Say what? Java has no notion of "generic package"! So what "problem"
> are you solving in Java?
> 
> If you change the problem statement to "create a class that can manage
> tasks that are all derived from a common Object type", then that is
> easily done in Ada!
> 
> --
> -- Stephe



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Generic Formal Parameter for a Task Type
  2001-03-09 21:50   ` Tucker Taft
  2001-03-10  0:14     ` Robert C. Leif, Ph.D.
@ 2001-03-10  3:25     ` James Rogers
  2001-03-12 15:33       ` Stephen Leake
  2001-03-12 16:11       ` Tucker Taft
  1 sibling, 2 replies; 18+ messages in thread
From: James Rogers @ 2001-03-10  3:25 UTC (permalink / raw)


Yes, each of these is a possible way to create a system for monitoring
and controlling a set of tasks. 

I like your idea of the abstract limited tagged type containing a
"Task_ID" function. Unfortunately, this still adds a lot of 
overhead when all I want to do is monitor and control the creation
of tasks.

Note that the problem I am trying to solve does not require much
knowledge about the task, only the ability to create an instance,
and the ability to query a task attribute.

I fully realize the problem can be solved by building an elaborate
scaffold of data and code structure. I was hoping to achieve the
results simply and cleanly. I was hoping to avoid the additional
overhead of code bloat resulting from building tagged types and
associated subprograms.

Jim Rogers
Colorado Springs, Colorado USA

Tucker Taft wrote:
> 
> Why not have a formal function that returns the Task_ID, rather
> than 'Terminated?  That way, you can use the Ada.Task_Identification
> and Ada.Task_Attributes packages to get whatever else you need from the
> task, including task attributes...
> 
> If you wanted to avoid generics, you could define an abstract limited
> tagged type (say "Has_Task") which had various (abstract) primitive
> operations, including  at least a "Task_ID" function.  You would then
> extend from this type by adding a component of the task type of interest
> (and of course override the abstract primitives as appropriate).
> You could then manipulate objects of type Has_Task'Class, or references
> there-to, in a "Java"-like way ;-).  You could also pass in any
> extension of Has_Task to a generic with a formal tagged derived type
> of "type My_Task is new Has_Task with private;".
> 
> The possibilities are endless...



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Generic Formal Parameter for a Task Type
  2001-03-10  3:25     ` James Rogers
@ 2001-03-12 15:33       ` Stephen Leake
  2001-03-12 16:11       ` Tucker Taft
  1 sibling, 0 replies; 18+ messages in thread
From: Stephen Leake @ 2001-03-12 15:33 UTC (permalink / raw)


James Rogers <jimmaureenrogers@worldnet.att.net> writes:

> Yes, each of these is a possible way to create a system for monitoring
> and controlling a set of tasks. 
> 
> I like your idea of the abstract limited tagged type containing a
> "Task_ID" function. Unfortunately, this still adds a lot of 
> overhead when all I want to do is monitor and control the creation
> of tasks.

By "overhead" here I guess you mean "code I have to write". The
implementation of the Java task hierarchy (which you are trying to get
in Ada) must have about the same amount of run-time "overhead", since
it does the same things. It's just that Java has already done the
implementation.

This is a _feature_ of Ada, since it lets you get exactly the
structure and semantics _you_ want, rather than the particular one the
Java language implementers decided to give you. Once someone has done
it and published it, you are free to reuse that, or do something
different. Java gives you no choice.

> Note that the problem I am trying to solve does not require much
> knowledge about the task, only the ability to create an instance,
> and the ability to query a task attribute.

Java gives you more than that, but you don't complain about "overhead"
there. 

> I fully realize the problem can be solved by building an elaborate
> scaffold of data and code structure. 

Similar to the one Java gives you.

> I was hoping to achieve the results simply and cleanly. 

Look at the Java code implementing the task hierarchy; is it simple
and clean?

> I was hoping to avoid the additional overhead of code bloat
> resulting from building tagged types and associated subprograms.

Be sure you are comparing the same things.

> 
> 
> Jim Rogers Colorado Springs, Colorado USA
> 
> Tucker Taft wrote:
> > 
> > Why not have a formal function that returns the Task_ID, rather
> > than 'Terminated?  That way, you can use the Ada.Task_Identification
> > and Ada.Task_Attributes packages to get whatever else you need from the
> > task, including task attributes...
> > 
> > If you wanted to avoid generics, you could define an abstract limited
> > tagged type (say "Has_Task") which had various (abstract) primitive
> > operations, including  at least a "Task_ID" function.  You would then
> > extend from this type by adding a component of the task type of interest
> > (and of course override the abstract primitives as appropriate).
> > You could then manipulate objects of type Has_Task'Class, or references
> > there-to, in a "Java"-like way ;-).  You could also pass in any
> > extension of Has_Task to a generic with a formal tagged derived type
> > of "type My_Task is new Has_Task with private;".
> > 
> > The possibilities are endless...

-- 
-- Stephe



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Generic Formal Parameter for a Task Type
  2001-03-10  3:25     ` James Rogers
  2001-03-12 15:33       ` Stephen Leake
@ 2001-03-12 16:11       ` Tucker Taft
  1 sibling, 0 replies; 18+ messages in thread
From: Tucker Taft @ 2001-03-12 16:11 UTC (permalink / raw)


James Rogers wrote:
> 
> Yes, each of these is a possible way to create a system for monitoring
> and controlling a set of tasks.
> 
> I like your idea of the abstract limited tagged type containing a
> "Task_ID" function. Unfortunately, this still adds a lot of
> overhead when all I want to do is monitor and control the creation
> of tasks.
> 
> Note that the problem I am trying to solve does not require much
> knowledge about the task, only the ability to create an instance,
> and the ability to query a task attribute.
> 
> I fully realize the problem can be solved by building an elaborate
> scaffold of data and code structure. I was hoping to achieve the
> results simply and cleanly. I was hoping to avoid the additional
> overhead of code bloat resulting from building tagged types and
> associated subprograms.

Actually, if you use limited tagged types, the "code bloat" is
pretty small (e.g. no automatically generated stream operations),
and unless you have a raft of different task types, there really
isn't much additional code to write.  Wrapping a task in a limited
(tagged) record doesn't actually increase the storage for the task
in any substantial way, and the additional code is just a short
Task_ID function per task type.
> 
> Jim Rogers
> Colorado Springs, Colorado USA

-- 
-Tucker Taft   stt@avercom.net   http://www.averstar.com/~stt/
Chief Technology Officer, AverCom Corporation (A Titan Company) 
Burlington, MA  USA (AverCom was formerly the Commercial Division of AverStar:
http://www.averstar.com/services/ebusiness_applications.html)



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Generic Formal Parameter for a Task Type
  2001-03-10  0:14     ` Robert C. Leif, Ph.D.
@ 2001-03-12 16:14       ` Tucker Taft
  0 siblings, 0 replies; 18+ messages in thread
From: Tucker Taft @ 2001-03-12 16:14 UTC (permalink / raw)


"Robert C. Leif, Ph.D." wrote:
> 
> From: Bob Leif
> To: Tucker Taft et al.
> You wrote:
> "If you wanted to avoid generics, you could define an abstract limited
> tagged type (say "Has_Task") which had various (abstract) primitive
> operations, including  at least a "Task_ID" function.  You would then
> extend from this type by adding a component of the task type of interest
> (and of course override the abstract primitives as appropriate)."
> 
> Can you include the "Has_Task" in a generic package; or are the two
> approaches mutually exclusive for tasks?

As I mentioned, you can declare a formal derived type, such as
   generic
       type My_Task is new Has_Task with private;
   ...

and inside the generic use the My_Task type to create tasks and
query the information about instances of the type.

I wrote earlier:
> ...
> Why not have a formal function that returns the Task_ID, rather
> than 'Terminated?  That way, you can use the Ada.Task_Identification
> and Ada.Task_Attributes packages to get whatever else you need from the
> task, including task attributes...
> 
> If you wanted to avoid generics, you could define an abstract limited
> tagged type (say "Has_Task") which had various (abstract) primitive
> operations, including  at least a "Task_ID" function.  You would then
> extend from this type by adding a component of the task type of interest
> (and of course override the abstract primitives as appropriate).
> You could then manipulate objects of type Has_Task'Class, or references
> there-to, in a "Java"-like way ;-).  You could also pass in any
> extension of Has_Task to a generic with a formal tagged derived type
> of "type My_Task is new Has_Task with private;".
> 
> The possibilities are endless...

-- 
-Tucker Taft   stt@avercom.net   http://www.averstar.com/~stt/
Chief Technology Officer, AverCom Corporation (A Titan Company) 
Burlington, MA  USA (AverCom was formerly the Commercial Division of AverStar:
http://www.averstar.com/services/ebusiness_applications.html)



^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2001-03-12 16:14 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-03-08 22:38 Generic Formal Parameter for a Task Type James Rogers
2001-03-08 23:27 ` Marin David Condic
2001-03-09  0:00 ` Robert A Duff
2001-03-09  0:16 ` Pat Rogers
2001-03-09  3:34   ` James Rogers
2001-03-09  4:26     ` Pat Rogers
2001-03-09  4:58       ` James Rogers
2001-03-09 15:50     ` Stephen Leake
2001-03-10  3:15       ` James Rogers
  -- strict thread matches above, loose matches on Subject: below --
2001-03-09  4:20 Beard, Frank
2001-03-09  5:24 ` James Rogers
2001-03-09 21:50   ` Tucker Taft
2001-03-10  0:14     ` Robert C. Leif, Ph.D.
2001-03-12 16:14       ` Tucker Taft
2001-03-10  3:25     ` James Rogers
2001-03-12 15:33       ` Stephen Leake
2001-03-12 16:11       ` Tucker Taft
2001-03-09 22:53 Beard, Frank

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