Ada 95 Quality and Style Guide Chapter 6

Chapter 6: Concurrency - TOC - 6.3 TERMINATION

6.3.4 Abnormal Termination

guideline

  • Place an exception handler for others at the end of a task body.
  • Consider having each exception handler at the end of a task body report the task's demise.
  • Do not rely on the task status to determine whether a rendezvous can be made with the task.

  • example

    This is one of many tasks updating the positions of blips on a radar screen. When started, it is given part of the name by which its parent knows it. Should it terminate due to an exception, it signals the fact in one of its parent's data structures:

    task type Track (My_Index : Track_Index) is
       ...
    end Track;
    ---------------------------------------------------------------------
    task body Track is
         Neutral : Boolean := True;
    begin  -- Track
       select
          accept ...
          ...
       or
          terminate;
       end select;
       ...
    exception
       when others =>
          if not Neutral then
             Station(My_Index).Status := Dead;
          end if;
    end Track;
    ---------------------------------------------------------------------
    

    rationale

    A task will terminate if an exception is raised within it for which it has no handler. In such a case, the exception is not propagated outside of the task (unless it occurs during a rendezvous). The task simply dies with no notification to other tasks in the program. Therefore, providing exception handlers within the task, and especially a handler for others, ensures that a task can regain control after an exception occurs. If the task cannot proceed normally after handling an exception, this affords it the opportunity to shut itself down cleanly and to notify tasks responsible for error recovery necessitated by the abnormal termination of the task.

    You should not use the task status to determine whether a rendezvous can be made with the task. If Task A depends on Task B and Task A checks the status flag before it rendezvouses with Task B, there is a potential that Task B fails between the status test and the rendezvous. In this case, Task A must provide an exception handler to handle the Tasking_Error exception raised by the call to an entry of an abnormal task (see Guideline 6.3.1).


    < Previous Page Search Contents Index Next Page >
    1 2 3 4 5 6 7 8 9 10 11
    TOC TOC TOC TOC TOC TOC TOC TOC TOC TOC TOC
    Appendix References Bibliography