Activation Group Considerations for the THREAD keyword
- Avoid running in the default activation group when the THREAD keyword is specified.
- With THREAD(*CONCURRENT), a program compiled with DFTACTGRP(*YES) cannot return with LR on or return abnormally if the program is currently running in another thread. When the program tries to deactivate itself, the deactivation will fail with MCH4405.
- With THREAD(*SERIALIZE), or THREAD(*CONCURRENT) where the SERIALIZE keyword is specified
on a procedure specification, if the program runs in the default activation group, the RPG
runtime cannot destroy the mutex used to serialize access to the module or the procedure.
In some cases, after the RPG program has ended, the pointer in the module's static storage
that points to the mutex will be deallocated or overwritten. This situation can cause a
storage leak, because the system's storage associated with the mutex is not freed when
the pointer to the mutex is lost. If the RPG program is called again, it will create a new
mutex.
This situation can arise in the following ways:
- The program is compiled with THREAD(*SERIALIZE) and DFTACTGRP(*YES), and the program ends with LR on, or it ends abnormally, which causes the program to be deactivated. When the program is deactivated, its static storage is deallocated.
- The RCLRSC command is used, and a program that uses a mutex to serialize a module or a procedure ran in the default activation group. A program will run in the default activation group if it is compiled with DFTACTGRP(*YES) or with ACTGRP(*CALLER), where the caller is in the default activation group.
- Avoid compiling with ACTGRP(*NEW) for programs that will run in a secondary thread. When a program compiled with ACTGRP(*NEW) ends in a secondary thread, the job will end with message CEE0200.