comp.lang.ada
 help / color / mirror / Atom feed
* Propagation of exceptions raised within tasks
@ 1986-06-02 16:16 frigo
  1986-06-04 14:13 ` Propagation of exceptions raised wit emery
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: frigo @ 1986-06-02 16:16 UTC (permalink / raw)


Re: Propagation of exceptions from tasks

Can anyone help me with this problem? It must e[Dbe a programming
error, but I can't find it...

The main procedure instantiates a package TASK_PAK, generic on
the number of tasks to be created. TASK_PAK declares an array
of records containing each a task component. The task body is
S[Dseparate(TASK_PAK).    

Each task has an exception handler of the form

    when OTHERS =>
       raise TASK_CH[DRASHED;

After starting all the tasks (they have an entry START) the main
procdu[D[Dedure goes in a loop in which it performs a selective entry
call to another task[D[D[D[D[D[D[D[D[D[D[D[D[D[CANOTHER task. The main procedure loop looks like this:

  begin
    loop
      select
        KEYBOARD.WAIT_FOR_SHUTDW[DOWN;
        ...
        exit;
      else
        delay 1 * SECS;
    end loop;
   [Dexception
    when TASK_CRASHED =>
      ...
  end;

Usin[D[D[D[DUsing the VAX/Ada de[D[D[D[D[D[D[D[D[D[Ddebugger under VAX/VMS, I can see the exception raisd[Ded
in one of the task being intercepted by the task excepion handler
and raised again as TASK_CRASHED.    However, the main program
stays de[D[DDELAYed on the selective entry call, and its exception
handler is not executed.    Why???

-- 
                       G. Vittorio FRIGO,
                       C.E.R.N., CH - 1211 Geneva 23, Switzerland

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

* Re: Propagation of exceptions raised wit
  1986-06-02 16:16 Propagation of exceptions raised within tasks frigo
@ 1986-06-04 14:13 ` emery
  1986-06-06 13:41   ` Doug Bryan
  1986-06-06 20:57 ` emery
  1986-06-20 15:05 ` Propagation of exceptions raised wi stt
  2 siblings, 1 reply; 5+ messages in thread
From: emery @ 1986-06-04 14:13 UTC (permalink / raw)




I think you are asking "Why don't exceptions propogate out of tasks?"
If so, don't feel bad, I asserted that they do once in public, and 
was quickly corrected.  

Exceptions do not propogate out of tasks.  If a task raises an exception
that it doesn't handle, the task becomes 'completed', but no further
action (including propogating the exception) takes place.

Quotes from the Canon:  Ada RM, section 11.4.1

"If an exception is raised in the sequence of statements of a frame that
does not have a handler for the exception, execution of the sequence
of statements is abandoned.  The next action depends on the nature of the
frame:

(a)  For a subprogram body, the same exception is raised again at the
point of call of the subprogram, unless the subprogram is the main
program itself, in which case execution of the main program is abandoned.

(b)  For a block statement, the same exception is raised again immediately
after the block statement (that is, within the innermost enclosing frame
or accept statement).

(c)  For a package body that is a declaritive item, the same exception
is raised again immediately after this declarative item (within the
enclosing declarative part).  If the package body is that of a subunit,
the exception is raised again at the place of the corresponding body
stub.  If the package is a library unit, execution of the main program
is abandoned.

(d)  For a task body, the task becomes completed.

An exception that is raised again (as in the above cases (a), (b), (c)) is
said to be propogated, either by the execution of the subprogram, the 
execution of the block statement, or the elaboration of the package body.
No propogation takes place in the case of a task body.  If the frame is 
a subprogram or a block statement and if it has dependent tasks, the 
propogation of an exception takes place only after termination of the
dependent tasks.  

Finally, if an exception is raised in the sequence of statements of an
exception handler, execution of this sequence of statements is abandoned.
Subsequent actions (including propogation, if any) are as in the cases
(a) to (d), above."


So, here's an interesting design problem:  How does a task report
failure due to an exception to its parent?

			Dave Emery
			Siemens Research
UUCP:	   ...princeton!siemens!emery
ARPA:	      princeton!siemens!emery@topaz.rutgers.edu

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

* Re: Propagation of exceptions raised wit
  1986-06-04 14:13 ` Propagation of exceptions raised wit emery
@ 1986-06-06 13:41   ` Doug Bryan
  0 siblings, 0 replies; 5+ messages in thread
From: Doug Bryan @ 1986-06-06 13:41 UTC (permalink / raw)



Dave,

also, don't forget that if an execption is raised during a rendezvous, it
is raised in the task being called and propagated to the calling task
as well.

doug
-------

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

* Re: Propagation of exceptions raised wit
  1986-06-02 16:16 Propagation of exceptions raised within tasks frigo
  1986-06-04 14:13 ` Propagation of exceptions raised wit emery
@ 1986-06-06 20:57 ` emery
  1986-06-20 15:05 ` Propagation of exceptions raised wi stt
  2 siblings, 0 replies; 5+ messages in thread
From: emery @ 1986-06-06 20:57 UTC (permalink / raw)




Both Frank Prindle and Doug Bryan have reminded me that, should an
exception be raised during rendeveous, the exception is propogated to
BOTH tasks.  This is perfectly consistent with the notion that the
rendeveous code is run 'by both tasks'.  

However, exception propogation, once inside the two tasks, follows
the rule I cited, i.e. the exception is not propogated out of either
task.

Thanks, guys.  

On a related topic:  A command interpreter is one good example of 
a program that may be called to invoke other programs, which are
not known at compile time (see Tom Wheeler's article, cited in 
previous discussions.)  If you presume that all such 'programs' are
tasks, here's my design problem again:  How does a task report
failure to its parent.  One of the problems here is the task name
problem.  A task does not know its identity, therefore it cannot say
things like "I am task 36, and I aborted because of a fubar exception."
The standard way around this is to "christen" the task through an 
entry call, where the caller tells the task its name ("You are task 36").
It seems that a task identity scheme is a necessary condition for having
tasks report their failure.

				Dave Emery
				Princeton Research
UUCP:		   ...princeton!siemens!emery	
ARPA:		      princeton!siemens!emery@topaz.rutgers.edu
					  or @seismo.css.gov

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

* Re: Propagation of exceptions raised wi
  1986-06-02 16:16 Propagation of exceptions raised within tasks frigo
  1986-06-04 14:13 ` Propagation of exceptions raised wit emery
  1986-06-06 20:57 ` emery
@ 1986-06-20 15:05 ` stt
  2 siblings, 0 replies; 5+ messages in thread
From: stt @ 1986-06-20 15:05 UTC (permalink / raw)



Quoting from the Ada RM, 11.4.1:4,8 ...
"If an exception is raised in the sequence of statements of a frame
that does not have a handler for the exception [ e.g.
your "raise TASK_CRASHED" ], execution of this sequence
of statements is abandoned.  The next action depends on
the nature of the frame:

. . .
  (d)  For a task body, the task becomes completed."

In other words, exceptions are not propagated out of task bodies.
Even the "master" is unaware that a task completed due to
an unhandled exception.  It only knows that the task completed somehow.

Just to confuse things, exceptions ARE propagated out
of accept bodies, to both the caller and the called task.

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

end of thread, other threads:[~1986-06-20 15:05 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1986-06-02 16:16 Propagation of exceptions raised within tasks frigo
1986-06-04 14:13 ` Propagation of exceptions raised wit emery
1986-06-06 13:41   ` Doug Bryan
1986-06-06 20:57 ` emery
1986-06-20 15:05 ` Propagation of exceptions raised wi stt

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