comp.lang.ada
 help / color / mirror / Atom feed
From: ncohen@watson.ibm.com (Norman H. Cohen)
Subject: Re: some questions re. Ada/GNAT from a C++/GCC user
Date: 1996/04/01
Date: 1996-04-01T00:00:00+00:00	[thread overview]
Message-ID: <4jp17p$17vn@watnews1.watson.ibm.com> (raw)
In-Reply-To: 4jhe1v$m0g@dayuc.dayton.saic.com

In article <4jhe1v$m0g@dayuc.dayton.saic.com>, John G. Volan
<John_Volan@ccmail.dayton.saic.com> writes: 

|> An Ada programmer would counter that, in Ada, some variables might be
|> instances of _task_ types.  By definition, a task object gets created
|> when its declaration is elaborated, but it does not get _activated_
|> (i.e., it doesn't start executing its statements) until you hit the
|> "begin" of the enclosing block.  This guarantees that everything in the
|> enclosing declarative region is elaborated before any a task starts up.

No, it doesn't guarantee that, because a task can also be created by an
ALLOCATOR in the declarative part, in which case it is activated
immediately.  Program_Error results if the task is activated before its
task body has been elaborated, so the fact that declarations in a
declarative part are elaborated in order is sufficient to guarantee that
any declaration referred to by the task unit has already been elaborated
by the time a task of the corresponding task type is activated.

|> In fact, _all_ the tasks in a declarative region are activated by the
|> "begin", simultaneously.  (Or virtually simultaneously. The point is,
|> Ada does not prescribe any particular order of activation, and does not
|> preclude truly simultaneous activation if the underlying run time
|> environment can support it.)  In effect, if a declarative region
|> contains tasks, then there is a synchronization point at the "begin"
|> which the Ada programmer can rely on.

All these complicated rules about activation (which originated in Ada
83) are actually there just for the sake of exception handling: If any
declared task fails during activation (i.e., raises an exception during
the elaboration of its task body's declarative part), Tasking_Error will
be raised in the associated sequence of statements.  Placing the nominal
point of activation just after the "begin" in the frame containing the
declaration means that the exception handlers of that frame can catch the
exception.  (This would not be the case if the Tasking_Error were raised
in declarative part.) Forcing the master frame to wait until all tasks
declared in the frame have been activated (or have died trying) allows
Tasking_Error to be raised exactly once in the master if one or more
dependent tasks have failed to activate.

There are at least three ways the rules of Ada could have allowed the
creator of a task to be informed about an unhandled exception in a task
it has created: 

  (a) Not at all.  In other words, the created task could die unnoticed,
      like Eleanor Rigby.
  (b) Asynchronously.  An exception could be raised, at an unpredictable
      time and place, in the creating task.
  (c) Synchronously.  An exception could be raised, if at all, at a
      predicatable time and place in the creating task.

Jean Ichbiah correctly saw the chaos that could result from approach (b).
He chose approach (c) for an exception occuring while the child task was
still elaborating the declarative part of its task body and (a) for an
exception occuring once the child task entered the sequence of statements
of its task body.  The problem with applying approach (a) in the
declarative part is that there is no way to handle the exception before
the execution of the task body is abandoned, since the handlers in the
task body do not apply to the declarative part.  Once the child has
reached adulthood, and is capable of handling its own exceptions, its
parent is no longer responsible for its sins.  (Anyone who has debugged a
program in which a task raised an unhandled exception has quickly learned
the value of adding a handler such as

   when others =>
      Display_Error_Message
         ("Task of type XYZ abandoned due to unhandled exception.");

to each task body.)

--
Norman H. Cohen    ncohen@watson.ibm.com




  parent reply	other threads:[~1996-04-01  0:00 UTC|newest]

Thread overview: 80+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-03-27  0:00 some questions re. Ada/GNAT from a C++/GCC user Bill Newman
1996-03-27  0:00 ` Robert Dewar
1996-03-28  0:00   ` Brian Rogoff
1996-03-29  0:00     ` John G. Volan
1996-03-30  0:00       ` Robert A Duff
1996-03-31  0:00         ` Robert Dewar
1996-04-01  0:00           ` Norman H. Cohen
1996-03-31  0:00         ` John G. Volan
1996-03-31  0:00           ` Mike Young
1996-04-02  0:00             ` Glenn H. Porter
1996-04-02  0:00               ` Robert Dewar
1996-04-02  0:00               ` Jonas Nygren
1996-04-03  0:00               ` Geert Bosch
1996-04-03  0:00                 ` Robert Dewar
1996-04-01  0:00           ` Bruce.Conroy
1996-04-01  0:00           ` Robert A Duff
1996-04-03  0:00             ` Scott Leschke
1996-04-04  0:00               ` AdaWorks
1996-03-30  0:00       ` Mike Young
1996-03-30  0:00         ` Ted Dennison
1996-03-31  0:00           ` Mike Young
1996-04-01  0:00       ` Norman H. Cohen [this message]
1996-04-01  0:00         ` Mike Young
1996-04-02  0:00           ` David Shochat
1996-04-02  0:00             ` Mike Young
1996-04-02  0:00           ` Norman H. Cohen
1996-04-02  0:00           ` Robert Dewar
1996-04-01  0:00         ` Robert A Duff
1996-04-01  0:00           ` Mike Young
1996-04-02  0:00             ` Robert A Duff
1996-04-02  0:00             ` Norman H. Cohen
1996-03-28  0:00   ` Norman H. Cohen
1996-03-28  0:00 ` Ted Dennison
1996-03-29  0:00   ` Adam Beneschan
1996-03-28  0:00 ` Scott Leschke
1996-03-29  0:00   ` Robert A Duff
1996-03-30  0:00     ` Richard Pitre
1996-03-30  0:00       ` Robert A Duff
1996-03-31  0:00         ` AdaWorks
1996-04-01  0:00           ` Robert A Duff
1996-04-01  0:00             ` AdaWorks
1996-04-01  0:00               ` Mike Young
1996-04-02  0:00                 ` Robert Dewar
1996-04-02  0:00                 ` AdaWorks
1996-04-01  0:00             ` Norman H. Cohen
1996-04-01  0:00             ` Ken Garlington
1996-04-01  0:00               ` Robert A Duff
1996-04-02  0:00                 ` Tucker Taft
1996-04-02  0:00                   ` Felaco
1996-04-02  0:00                     ` Robert Dewar
1996-04-03  0:00                     ` Mark A Biggar
1996-04-02  0:00                 ` Ken Garlington
1996-04-02  0:00                   ` Robert A Duff
1996-04-02  0:00                     ` Ken Garlington
1996-04-02  0:00                       ` Robert A Duff
1996-04-03  0:00                         ` Ken Garlington
1996-04-09  0:00                           ` Matt Kennel
1996-04-03  0:00                         ` David Emery
1996-04-01  0:00         ` Robert Dewar
1996-04-01  0:00         ` Richard A. O'Keefe
1996-04-01  0:00           ` Robert A Duff
1996-04-02  0:00       ` Robert I. Eachus
1996-03-29  0:00   ` Robert I. Eachus
1996-03-29  0:00   ` Bill Newman
1996-03-29  0:00 ` Robert A Duff
1996-03-29  0:00   ` Brian Rogoff
1996-04-01  0:00     ` Mark A Biggar
1996-04-01  0:00       ` Robert A Duff
1996-03-30  0:00   ` Iterators (was Re: some questions re. Ada/GNAT from a C++/GCC user) Robert I. Eachus
1996-03-31  0:00     ` Mike Young
1996-03-31  0:00       ` Fergus Henderson
     [not found]   ` <4jlj79$h1k@Nntp1.mcs.net>
1996-04-01  0:00     ` some questions re. Ada/GNAT from a C++/GCC user Robert A Duff
1996-04-02  0:00       ` Kevin Cline
1996-04-02  0:00         ` Robert A Duff
1996-04-01  0:00   ` Iterators (was Re: some questions re. Ada/GNAT from a C++/GCC user) Robert I. Eachus
1996-04-04  0:00   ` some questions re. Ada/GNAT from a C++/GCC user Jon S Anthony
1996-03-30  0:00 ` Simon Wright
1996-04-01  0:00 ` Laurent Guerby
1996-04-01  0:00   ` Robert A Duff
  -- strict thread matches above, loose matches on Subject: below --
1996-03-28  0:00 Simon Johnston
replies disabled

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