Activation groups and threads

All programs and service programs are activated within a substructure of a job that is called an activation group. This substructure contains the resources necessary to run the programs, including static and heap storage, and temporary data management resources.

Start of changeIn a job capable of multithreaded operation, two or more threads can share an activation group. A thread can run programs that were activated in different activation groups. The system does not keep a list of threads that run in an activation group nor does it keep a list of activation groups in a thread. Ending an activation group with active threads in it can produce unpredictable results including an abnormal end of the job. To avoid these problems in IBM® i 6.1 and earlier releases, any action that ends an activation group in a secondary thread causes the system to end the job in an orderly fashion. In other words, the system ends all threads in the job, calls exit routines and C++ destructors in the initial thread, and finally closes the files. Beginning with IBM i 7.1, the job is ended only if the activation group being ended is active in more than one thread. An activation group is considered to be active in a thread if it has one or more invocations on the call stack for the thread.End of change

When you work with activation groups, be aware of the following considerations:
  • Return from activation groups

    Start of changeA program that is created with ACTGRP(*NEW) gets a new activation group every time it is called. When the program returns, the new activation group ends.End of change

    Start of changeBoth default and user-named activation groups are persistent. Default activation groups are created when a job starts and destroyed only when the job ends. User-Named activation groups are created when they are first needed in a job. A normal return from the user-named activation group leaves the activation group in last-used state, but does not end the activation group. End of change

  • End verb
    Start of changeIf a high-level language (HLL) end verb like exit() or abort() is called and the nearest control boundary is the primary entry point for the program, the activation group is ended. If the nearest control boundary is not the primary entry point for the program, the activation group is not ended.
    Note: In IBM i 6.1 and earlier releases, the job is ended whenever an HLL end verb is called from a secondary thread, even if the activation group is not ended.
    End of change
  • Unhandled exceptions

    Start of changeIf an exception has not been handled by the time it has percolated to a control boundary and the control boundary is the oldest call stack entry in the activation group, the activation group is ended.End of change

  • Reclaim activation group (RCLACTGRP)

    Jobs capable of multithreaded operation allow this command to be called only in the initial thread in the job. If secondary user threads are present in the job, this command sends a CPF180B escape message to the caller of the command.