Threadsafe programs

In the CICS® open transaction environment (OTE), when application programs, task-related user exits (TRUEs), global user exit programs, and user-replaceable modules are defined to CICS as threadsafe, they can run concurrently on open TCBs.

Accessing the OTE

Applications that involve a TRUE enabled using the OPENAPI option on the ENABLE PROGRAM command are automatically involved with the OTE. These applications can gain performance benefits from being threadsafe. For example the CICS DB2® task-related user exit used by CICS applications that access DB2 resources is an open API TRUE, so CICS DB2 applications can gain performance benefits from being threadsafe.

For other user application programs, PLT programs, user replaceable modules, or task-related user exits, you can opt to use the OTE by defining them as OPENAPI programs, in which case they must be threadsafe.

If you define your program as CONCURRENCY(REQUIRED) it always runs on an open TCB. The type of open TCB used depends on the API setting. For CICSAPI programs, CICS uses an L8 open TCB regardless of the execution key of the program. For OPENAPI programs, CICS uses an L9 TCB if EXECKEY(USER) is set and an L8 TCB if EXECKEY(CICS) is set. REQUIRED is applicable to user application programs, PLT programs, and user replaceable modules. For global user exit programs and task-related user exit programs, if you specify CONCURRENCY(REQUIRED), CICS treats the program as if you had specified CONCURRENCY(THREADSAFE).

Global user exits cannot be defined as OPENAPI programs, but if you use the THREADSAFE option on the ENABLE PROGRAM command for a global user exit, it is enabled as a threadsafe program and can run on the same open TCB as an application that uses it. If the ENABLE PROGRAM command does not specify the CONCURRENCY or API options then the options on the program definition are used.

The following table shows the CONCURRENCY and API settings that are available on the program, and the type of TCB that the application program is run on.

Table 1. Combination of PROGRAM CONCURRENCY and API settings and the type of TCB used.
CONCURRENCY attribute API attribute CICS TCB
CONCURRENCY(QUASIRENT) API(CICSAPI) The application program always runs under the CICS quasi-reentrant (QR TCB). If a switch to an open TCB occurs for a resource manager, CICS always returns to QR TCB before returning to the application.
CONCURRENCY(QUASIRENT) API(OPENAPI) Invalid combination. OPENAPI programs cannot run on a QR TCB.
CONCURRENCY(THREADSAFE) API(CICSAPI) The application program can run on a QR TCB or an open TCB. If a switch to an open TCB occurs for a resource manager, CICS stays on the open TCB when returning to the application. If a switch to the QR TCB occurs, CICS stays on QR TCB when returning to the application.
CONCURRENCY(THREADSAFE) API(OPENAPI) Same as CONCURRENCY(REQUIRED) API(OPENAPI).
CONCURRENCY(REQUIRED) API(CICSAPI) The application program always runs on an open TCB. CICS services do not require TCB key matching so the application always runs on a L8 open TCB. An OPENAPI resource manager uses an L8 TCB so no TCB switch is required if it is invoked. If a switch to the QR TCB occurs, CICS returns to the open TCB when returning to the application.
CONCURRENCY(REQUIRED) API(OPENAPI) The application program always runs on an open TCB. The key of the TCB must match the execution key of the program. CICS uses an L9 TCB if EXECKEY(USER) is set and an L8 TCB if EXECKEY(CICS) is set. If the application is user key and an OPENAPI resource manager is invoked then a switch occurs from the L9 TCB to the L8 TCB. CICS returns to L9 TCB before returning to the application. If a switch to the QR TCB occurs, CICS returns to the open TCB when returning to the application.

Defining a program as threadsafe when it is not threadsafe

If you define a program to CICS as threadsafe but include application logic that is not threadsafe, the results are unpredictable, and CICS is not able to protect you from the possible consequences.


threadsafe_program.html | Timestamp icon Last updated: Thursday, 27 June 2019