On Linux (kernel 2.6.5) our build system calls gcc with -D_REENTRANT
.
Is this still required when using pthreads
?
How is it related to gcc -pthread
option? I understand that I should use -pthread
with pthreads, do I still need -D_REENTRANT
?
On a side note, is there any difference that you know off between the usage of REENTRANT between gcc 3.3.3 and gcc 4.x.x ?
When I use -pthread
gcc option I can see that _REENTRANT
gets defined. Will omitting -D_REENTRANT
from command line make any difference, for example could some objects be compiled without multithreaded support and then linked into binary that uses pthreads and will cause problems?
I assume it should be ok just to use: g++ -pthread
> echo | g++ -E -dM -c - > singlethreaded
> echo | g++ -pthread -E -dM -c - > multithreaded
> diff singlethreaded multithreaded
39a40
> #define _REENTRANT 1
We're compiling multiple static libraries and applications that link with the static libraries, both libraries and application use pthreads.
I believe it was required at some stage in the past but want to know if it is still required. Googling hasn't returned any recent information mentioning -D_REENTRANT
with pthreads
. Could you point me to links or references discussing the use in recent version of kernel/gcc/pthread?
Clarification: At the moment we're using -D_REENTRANT and -lpthread, I assume I can replace them with just g++ -pthread, looking at man gcc it sets the flags for both preprocessor and linker. Any thoughts?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…