Writing and compiling threaded programs
When writing and compiling code that use threads or that run in a threaded job, make sure to do the following:
- Ensure that all of the APIs or system services that you use are threadsafe.
See Multithreaded applications for an
introduction to threads and general information about IBM® i threads.
- Insert the following lines into any module that uses the thread data types
or definitions.
#define _MULTI_THREADED
#include <pthread.h>
The preprocessor definition _MULTI_THREADED must come before the pthread.h.
See Header files for Pthread functions for more information about header files.
See Using the _MULTI_THREADED preprocessor definition for more information about the _MULTI_THREADED preprocessor definition.
- Compile the program normally; use the CRTCMOD followed by
the CRTPGM or CRTSRVPGM commands. You can
also use the CRTBNDC CL command to create your threaded
program.
- Since Pthread APIs can operate on functions and data which could exist in different compilation units (modules), the same storage model and data model must be used throughout all compilation units within a program or service program that uses Pthread APIs. Otherwise, unpredictable behavior and failures will occur. See the information about teraspace and single-level store in the ILE Concepts manual for more information about storage model and data model.
[ Back to top | Pthread APIs | APIs by category ]