comp.lang.ada
 help / color / mirror / Atom feed
From: arny@wayback.UUCP (Arny B. Engelson)
Subject: Re: Pre-elaboration Problems
Date: Mon, 5-Jan-87 17:25:06 EST	[thread overview]
Date: Mon Jan  5 17:25:06 1987
Message-ID: <1023@wayback.UUCP> (raw)
In-Reply-To: 8701010253.AA21054@ucbvax.Berkeley.EDU

In article <8701010253.AA21054@ucbvax.Berkeley.EDU>, wilson%anchor.DECnet@lll-icdc.arpa ("ANCHOR::WILSON") writes:

(Package spec here containing generic package with generic formal subprogram
as one of the parameters, and a procedure within the generic package that is
called by the subprogram supplied by the user as the actual to the generic).

(main program contains declaration of subprogram to be passed, instantiation
of generic package, then the body of the previously declared subprogram.
Program_Error is raised because something in the instantiated generic invokes
the user's subprogram before the body of the subprogram is elaborated).

(two unsatisfactory solutions here).

> My questions to the Ada community are these:
> 
> 	o  Is there a Solution 3?
Yes, I think so.  See my comments on the program below.
> 
> 	o  Can anyone make me feel better about Solutions 1 or 2?
Solution 2 is better than solution 1.
> 
> 	o  How can I convince myself that my program isn't some day going
> 	   to call an unelaborated routine?  Is there a simple checklist
> 	   I can use?
Use careful design, keep reading the LRM, and hope the rules don't change
too often.  I've run into similar order-of-elaboration problems and have no
checklist to offer.

> Finally, why don't I get a PROGRAM_ERROR on the following program?  It seems
> like as soon as the main task has elaborated task T, T should start running
> (given the higher priority) before P is elaborated . . . .
> (I compiled and ran this using VAX Ada on a VAX 11/750.)
> 
> 	with TEXT_IO;	use TEXT_IO;
> 	with SYSTEM;
> 	procedure TEST_1 is
> 	    task T is
> 		pragma PRIORITY( SYSTEM.PRIORITY'last );
> 	    end T;
> 	    procedure P;
> 	    task body T is
> 	    begin  P;  end T;
> 	    procedure P is
> 	    begin  PUT_LINE( "Hi!" );  end P;
> 	begin null; end TEST_1;
> 
> 			--- Rick Wilson
> wilson%anchor.decnet@lll-icdc.arpa
> (415) 423-6662


   I believe the appropriate reference is LRM 9.3:2, which states:
"activation of the task object starts after the elaboration of the declarative
part (that is, after passing the reserved word BEGIN following the declarative
part)".
   Therefore, task T doesn't begin executing until after the body of procedure
P is elaborated.
   It would follow that you could solve the first problem by using a task to
delay the execution of the instantiated package until everything was
elaborated.  Perhaps by encapsulating the instantiation of the generic within
a task.  I haven't the time to search for an exact solution, but I think this
is a worthwhile direction to explore.

Arny B. Engelson
{bonnie|clyde|ihnp4}!wayback!arny
AT&T Bell Laboratories, Whippany, N.J.
(201) 386-4816

  reply	other threads:[~1987-01-05 22:25 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1986-12-30  3:27 Pre-elaboration Problems "ANCHOR::WILSON"
1987-01-05 22:25 ` Arny B. Engelson [this message]
  -- strict thread matches above, loose matches on Subject: below --
1986-12-30  3:27 "ANCHO
replies disabled

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