Multithreaded Programming Guide

Defining _REENTRANT or _POSIX_C_SOURCE

For POSIX behavior, compile applications with the -D_POSIX_C_SOURCE flag set >= 199506L. For Solaris behavior, compile multithreaded programs with the -D_REENTRANT flag. This applies to every module of an application.

For mixed applications (for example, Solaris threads with POSIX semantics), compile with the -D_REENTRANT and -D_POSIX_PTHREAD_SEMANTICS flags.

To compile a single-threaded application, define neither the -D_REENTRANT nor the -D_POSIX_C_SOURCE flag. When these flags are not present, all the old definitions for errno, stdio, and so on, remain in effect.


Note -

Compile single-threaded applications, not linked with either of the thread libraries (libthread.so.1 or libpthread.so.1), without the -D_REENTRANT flag. This eliminates performance degradation incurred when macros, such as putc(3s), are converted into reentrant function calls.


To summarize, POSIX applications that define -D_POSIX_C_SOURCE get the POSIX 1003.1c semantics for the routines listed in Table 7-1. Applications that define only -D_REENTRANT get the Solaris semantics for these routines. Solaris applications that define -D_POSIX_PTHREAD_SEMANTICS get the POSIX semantics for these routines, but can still use the Solaris threads interface.

Applications that define both -D_POSIX_C_SOURCE and -D_REENTRANT get the POSIX semantics.