Threads considerations for ILE RPG language

An Integrated Language Environment (ILE) RPG module that runs safely in a multithreaded environment can be created by creating the module to have thread-scoped static storage, or by serializing access to the module.

You can create the module to have all its static storage default to thread-scoped static storage by specifying THREAD(*CONCURRENT) on the Control specification.

You can serialize access to the module by specifying THREAD (*SERIALIZE) on the Control specification. After you serialize a module, only one thread can run any procedure in that module at one time. For example, consider a module that has procedures P1 and P2. If one thread is running procedure P1, no other thread can run either procedure P1 or P2 until the first thread finishes running P1.

Even when a module uses thread-scoped static storage or the module is serialized, the RPG programmer must ensure that non-thread-scoped static storage, storage that is shared through import or export, and heap storage are accessed in a threadsafe way. Even if an RPG procedure apparently uses only automatic storage, RPG uses static storage control blocks in every procedure. Therefore, you must always specify THREAD(*CONCURRENT) or THREAD(*SERIALIZE) when using ILE RPG in a multithreaded environment.