When writing any code that will use threads or run in a threaded job, you should ensure that ALL APIs or system services you use are thread safe.
Use normal processes for compiling the program. Use the CRTCMOD followed by CRTPGM or CRTSRVPGM commands. You can also use the CRTBNDC CL command to create your threaded program.
In addition, you must define the preprocessor definition _MULTI_THREADED in your source.
The _MULTI_THREADED preprocessor definition is required either in the source file prior to including pthread.h or on the compiler invocation. This preprocessor value allows the system to support both the old model toolkit threads and the new kernel thread APIs in a compatible fashion. The _MULTI_THREADED preprocessor value is used to indicate that your application uses the newer kernel threads model. The preprocessor value may also be used by other parts of the system in order to create thread safe macros. (For example, the fputc() macro of the C runtime could use this preprocessor value. You should always define this macro in source files that will run in a kernel threaded job.)
If you do not define _MULTI_THREADED when you include the pthread.h header file, the system will interpret this as a request to compile for CPA toolkit threads (simulation of threads based on the process model). If the CPA toolkit is not present on the system, your compile will fail.
You should insert the following lines into any module that uses the thread data types or definitions.
#define _MULTI_THREADED #include <pthread.h>
In release V4R2, these header files are only available on your system if you have also loaded and applied the limited availability PTF or I-Listed PRPQ that provides the header file support. The PTF number is 5769SS1-J664741. The I-Listed PRPQ number is yet to be provided.
Where to Find Header Files
| Name of Header File | Name of File in QSYSINC | Name of Member |
| pthread.h | H | PTHREAD |
| sched.h | H | SCHED |
STRSEU SRCFILE(QSYSINC/H) SRCMBR(PTHREAD) OPTION(5)
DSPPFM FILE(QSYSINC/H) MBR(SCHED)You can print a header file in QSYSINC by using one of the following methods:
STRSEU SRCFILE(QSYSINC/H) SRCMBR(PTHREAD) OPTION(6)
CPYF FROMFILE(QSYSINC/H) TOFILE(*PRINT) FROMMBR(SCHED)
The QUSRTOOL library also provides source code and an example CL command to allow you to create and use a SPAWN CL command in a fashion that is similar to the SMBJOB CL command. See "SPAWN CL command, QUSRTOOL example" on page 52 for more information.