Writing z/OS UNIX System Services applications
The batch adapter supports queue manager connections from batch and TSO address spaces:
If we consider a Batch address space, the adapter supports connections from multiple TCBs within that address space as follows:- Each TCB can connect to multiple queue managers using the MQCONN or MQCONNX call (but a TCB can only have one instance of a connection to a particular queue manager at any one time).
- Multiple TCBs can connect to the same queue manager (but the queue manager handle returned on any MQCONN or MQCONNX call is bound to the issuing TCB and cannot be used by any other TCB).
z/OS UNIX System Services supports two types of pthread_create call:
- Heavyweight threads, run one for each TCB, that are ATTACHed and DETACHed at thread start and end by z/OS.
- Medium-weight threads, run one for each TCB, but the TCB can be one of a pool of long-running TCBs. The application must perform all necessary application cleanup, because, if it is connected to a server, the default thread termination that might be provided by the server at task (TCB) termination, is not always driven.
Lightweight threads are not supported. (If an application creates permanent threads that dispatch their own work requests, the application is responsible for cleaning up any resources before starting the next work request.) IBM MQ for z/OS supports z/OS UNIX System Services threads using the Batch Adapter as follows:
- Heavyweight threads are fully supported as batch connections. Each thread runs in its own TCB, which is attached and detached at thread start and end. Should the thread end before issuing an MQDISC call, IBM MQ for z/OS performs its standard task cleanup, which includes committing any outstanding unit of work if the thread terminated normally, or backing it out if the thread terminated abnormally.
- Medium-weight threads are fully supported, but if the TCB is going to be reused by another thread, the application must ensure that an MQDISC call, preceded by either MQCMIT or MQBACK, is issued before the next thread start. This implies that if the application has established a Program Interrupt Handler, and the application then abends, the Interrupt Handler must issue MQCMIT and MQDISC calls before reusing the TCB for another thread.
Note: Threading models do not support access to common IBM MQ resources from multiple threads. Parent topic: Use and writing applications on IBM MQ for z/OS