From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=BAYES_00,INVALID_DATE autolearn=no autolearn_force=no version=3.4.4 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!elma.epfl.ch!madmats From: madmats@elma.epfl.ch (Mats Weber) Newsgroups: comp.lang.ada Subject: Two Questions on tasking Message-ID: <890331161111.20401e9f@elcc.epfl.ch> Date: 31 Mar 89 15:11:11 GMT Sender: daemon@ucbvax.BERKELEY.EDU Organization: The Internet List-Id: > 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