The POSIX standard for the threads library specifies the implementation of some parts as optional. All subroutines defined by the threads library API are always available. Depending on the available options, some subroutines may not be implemented. Unimplemented subroutines can be called by applications, but they always return the ENOSYS error code.
Read the following to learn more about threads library options:
The following options are defined:
The priority inheritance and priority protection options require the implementation of the priority scheduling option.
The stack address option enables the control of the stackaddr attribute of a thread attributes object. This attribute specifies the location of storage to be used for the created thread's stack. See "Stack Address for more information about the stackaddr attribute.
The following attribute and subroutines are available when the option is implemented:
The stack size option enables the control of the stacksize attribute of a thread attributes object. This attribute specifies the minimum stack size to be used for the created thread. See "Stack Size for more information about the stacksize attribute.
The following attribute and subroutines are available when the option is implemented:
The priority scheduling option enables the control of execution scheduling at thread level. When this option is disabled, all threads within a process share the scheduling properties of the process. When this option is enabled, each thread has its own scheduling properties. For local contention scope threads, the scheduling properties are handled at process level by a library scheduler, while for global contention scope threads, the scheduling properties are handled at system level by the kernel scheduler. See Threads Scheduling to get more information about the scheduling properties of a thread.
The attributes and subroutines shown below are available when the option is implemented:
Options can be checked at compile time (Compile Time Checking) or at run time (Run Time Checking). Portable programs should check the availability of options before using them, so that they do not need to be rewritten when ported to other systems.
Symbolic constants (symbols) can be used to get the availability of options on the system where the program is compiled. The symbols are defined in the pthread.h header file by the #define pre-processor command. For unimplemented options, the corresponding symbol is undefined by the #undef pre-processor command. Checking option symbols should be done in each program that may be ported to another system.
The following list indicates the symbol associated with each option:
The simplest action to take when an option is not available is to stop the compilation, as in the following example:
#ifndef _POSIX_THREAD_ATTR_STACKSIZE #error "The stack size POSIX option is required" #endif
The pthread.h header file also defines the following symbols that can be used by other header files or by programs:
_POSIX_REENTRANT_FUNCTIONS | Denotes that reentrant functions are required. |
_POSIX_THREADS | Denotes the implementation of the threads library. |
The sysconf subroutine can be used to get the availability of options on the system where the program is executed. This is useful when porting programs between systems that have a binary compatibility, such as two versions of AIX.
The following list indicates the symbolic constant associated with each option and that must be used for the Name parameter of the sysconf subroutine. The symbolic constants are defined in the unistd.h header file.
Two general options may also be checked using the sysconf subroutine with the following Name parameter values:
_SC_REENTRANT_FUNCTIONS | Denotes that reentrant functions are required. |
_SC_THREADS | Denotes the implementation of the threads library. |
Threads Programming Guidelines.
Threads Library Quick Reference.