Module 14: CICS Performance, Security and Advanced Topics
Threadsafe Programming
Threadsafe programming lets CICS run your program on many processors at the same time. It is the biggest single performance improvement available to old CICS applications.
Quasireentrant vs threadsafe
- Old CICS programs run on one special task control block called the QR TCB. Only one QR program runs at a time per region.
- A threadsafe program can run on open TCBs (L8 and L9). Many threadsafe programs can run at the same time on different processors.
- If your program is not threadsafe, CICS switches it back to the QR TCB automatically. This is safe but slow.
- CONCURRENCY(THREADSAFE) on the PROGRAM definition tells CICS your program is safe to run on an open TCB.
PROGRAM attributes
- CONCURRENCY(QUASIRENT): the program always runs on the QR TCB. This is the default.
- CONCURRENCY(THREADSAFE): the program can run on an open TCB, but CICS switches it to QR for any command that is not threadsafe.
- CONCURRENCY(REQUIRED): the program must stay on an open TCB. Use it with API(OPENAPI) for programs that call non-CICS APIs.
- API(CICSAPI) means the program uses only EXEC CICS commands. API(OPENAPI) allows other APIs like POSIX calls or Java.
Making a program threadsafe
- Do not use storage that is shared between tasks unless access is serialized with ENQ and DEQ.
- Avoid static working storage that one task can change while another task reads it. Use task-lifetime storage from GETMAIN.
- Most EXEC CICS commands are threadsafe. Check the documentation for the few that force a switch back to QR.
- You can set defaults with the CICSVAR environment variable. CICSVAR=THREADSAFE gives CONCURRENCY(THREADSAFE) with API(CICSAPI).
- Test threadsafe programs under heavy parallel load. Timing bugs only appear when many tasks run together.
Example: defining a threadsafe program
- Set the attributes on the PROGRAM resource definition with CEDA.
- CEDA DEFINE PROGRAM(PAYUPD) GROUP(PAYGRP) LANGUAGE(COBOL) CONCURRENCY(THREADSAFE) API(CICSAPI)
- After installing the definition, the program can run on open TCBs whenever it issues threadsafe commands.
- Use CEMT INQUIRE PROGRAM to confirm the CONCURRENCY and API settings are active.
