What is the _REENTRANT flag?

Vijay picture Vijay · Apr 8, 2010 · Viewed 14.6k times · Source

which compiling a multithreaded program we use gcc like below:

gcc -lpthread -D_REENTRANT -o someprogram someprogram.c

what exactly is the flag -D_REENTRANT doing over here?

Answer

JayM picture JayM · Apr 8, 2010

Defining _REENTRANT causes the compiler to use thread safe (i.e. re-entrant) versions of several functions in the C library.

You can search your header files to see what happens when it's defined.