comp.lang.ada
 help / color / mirror / Atom feed
From: madmats@elma.epfl.ch (Mats Weber)
Subject: Two Questions on tasking
Date: 31 Mar 89 15:11:11 GMT	[thread overview]
Message-ID: <890331161111.20401e9f@elcc.epfl.ch> (raw)

> Date: 29 Mar 89 09:16:26 GMT
> From: mcvax!hp4nl!uva!mel!hm@uunet.uu.net  (HansM)
> Subject: Two questions
>
> We are trying to understand Ada tasking and there are two things we fail to
> understand:
>
> 1. When an exception is raised and not handled in a task body, the task
>    is terminated and the exception is not further propagated, without
>    notice (11.4.1.8).  Why is this?

This is because the execution of the task is independent of its creator. If
the exception were propagated to the task's creator, the exception handler in
the creator could get exceptions from all tasks he has created.
For example, if task A creates A.B, A.C and A.D and A.B raises Exception_B
and A.C raises exception Exception_C, how would the handler in A deal with
them ?
The Ada rules on exceptions state that only one exception may be active in any
thread of execution.

>    Is there a way to invoke the kind of traceback that occurs when an
>    exception is propagated out of the main program?

This is system dependant. Some systems notify you when an unhandled exception
terminates a task, others don't.
If you want to be shure, add handlers to your tasks that notify you when they
terminate as the result of an exception (be careful with Text_IO being called
by multiple tasks, use semaphores).

> 2. When a task has completed its execution, termination is delayed until all
>    dependent tasks have terminated (9.4.6).  As a result, our program
>    fills up all memory with completed tasks unable to terminate.  Why is
>    this?  Can something be done about it (without altering task dependency)?

Termination of tasks is a high level concept used in the LRM and has nothing
to do with memory use and reclamation. I know some systems implement memory
deallocation for tasks very poorly. A good workaround is to reuse your tasks
as described in another reply.

The reason why a task's termination is delayed until all dependent tasks have
terminated can be seen in the following example:

procedure Main_Program is

   task T1;

   task T3;

   task body T1 is

      task T2;

      Local : Integer;

      task body T2 is
      begin
         ...
         Some_Action(Local);
         ...
      end T2;

   begin
      ...
   end T1;

   task body T3 is ...;

begin
   ...
end Main_Program;

If T1 completes before T2 terminates, it must wait for it because T2 may use
local items declared in T1. For the same reason, the main program must wait
for T1 and T3 to terminate. On the other hand, the termination of T1 and T3 is
independent.

Mats Weber
Swiss Federal Institute of Technology
EPFL DI LITh
1015 Lausanne
Switzerland

e-mail : madmats@elma.epfl.ch

             reply	other threads:[~1989-03-31 15:11 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1989-03-31 15:11 Mats Weber [this message]
1989-03-31 21:42 ` Two Questions on tasking Bob Hathaway
  -- strict thread matches above, loose matches on Subject: below --
1989-04-03 11:05 Two Questions on Tasking Mats Weber
1989-04-03 13:31 Two Questions on tasking Norman Cohen
replies disabled

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