我需要在编译时添加一个_REENTRANT宏,以使我的errno线程安全吗? [英] Is it required for me to add a _REENTRANT macro during compile time to make my errno thread safe?
问题描述
我需要在编译期间添加一个_REENTRANT宏以使我的errno线程安全吗?
如果不是,是所有版本的gcc / linux / solaris或某些旧版本是否需要它?
我最近测试了一段没有使用_REENTRANT的代码,发现errno在未定义的fahsion多线程环境?但是,添加_REENTRANT后,一切工作正常。环境是Solaris。
但是,讨论这里似乎没有说是强制要添加_REENTRANT。我有点困惑。
此外,除了_REENTRANT之外,我应该添加任何其他选项或lib,以确保我的应用程序有一个线程安全的错误?
理论,POSIX要求您通过 getconf
查询和使用以下配置选项:
-
POSIX_V7_THREADS_LFLAGS
-
POSIX_V7_THREADS_LDFLAGS
另一方面,gcc有自己冲突的可移植方式来请求线程支持:-pthread
/ code>选项,通常添加任何预定义的宏和线程工作所需的库。
Is it required for me to add a _REENTRANT macro during compile time to make my errno thread safe?
If no, is it the case for all versions of gcc / linux / solaris or is it required for certain old versions?
I recently tested a piece of code where _REENTRANT was not used and found the errno behaving in an undefined fahsion in multi thread environment? But, after adding _REENTRANT everything was working fine. The Environment was Solaris.
But, the discussion here doesn't seem to say it is mandatory to add _REENTRANT. I am a little confused.
Also, apart from _REENTRANT should I add be adding any other options or libs to ensure my application has a thread safe errno?
In practice, _REENTRANT
is legacy junk from a time when threads were considered an extension hacked on top of existing implementations, and the default behavior of the standard library was not thread-safe. It should not be needed on modern implementations, and it was never standard. (Note that it's also a misnomer, since reentrant and thread-safe have radically different meanings.)
In theory, POSIX requires you to query and use the following configuration options via getconf
if you're compiling a threaded program:
POSIX_V7_THREADS_CFLAGS
POSIX_V7_THREADS_LDFLAGS
On the other hand, gcc has its own conflicting "portable" way to request thread support: the -pthread
option, which normally adds any predefined macros and libraries needed for threads to work.
这篇关于我需要在编译时添加一个_REENTRANT宏,以使我的errno线程安全吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!