我需要在编译时添加一个_REENTRANT宏,以使我的errno线程安全吗? [英] Is it required for me to add a _REENTRANT macro during compile time to make my errno thread safe?

查看:243
本文介绍了我需要在编译时添加一个_REENTRANT宏,以使我的errno线程安全吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在编译期间添加一个_REENTRANT宏以使我的errno线程安全吗?



如果不是,是所有版本的gcc / linux / solaris或某些旧版本是否需要它?



我最近测试了一段没有使用_REENTRANT的代码,发现errno在未定义的fahsion多线程环境?但是,添加_REENTRANT后,一切工作正常。环境是Solaris。



但是,讨论这里似乎没有说是强制要添加_REENTRANT。我有点困惑。



此外,除了_REENTRANT之外,我应该添加任何其他选项或lib,以确保我的应用程序有一个线程安全的错误?

_REENTRANT 是从线程被认为是在现有实现之上被破解的时候的遗留垃圾,并且标准库的默认行为不是线程安全的。它不应该在现代实现上需要,并且它从来不是标准的。 (请注意,这也是一个不当名词,因为可重入线程安全具有完全不同的含义。)



理论,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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆