问题描述
是错误号
上MSVC线程安全的?
Is errno
on MSVC thread-safe?
根据这个问题 POSIX要求错误号
是线程安全的。但是MSVC大概POSIX不兼容和不告诉线程安全的东西。 MSDN矛盾提到错误号
声明为的extern INT错误号;
,又可作为的#define错误号(* _errno())
According to the answers in this question POSIX requires that errno
is thread-safe. But MSVC is probably not POSIX compliant and MSDN does not tell anything about thread-safety. MSDN contradictory mentions that errno
is declared as extern int errno;
, but also as #define errno (*_errno())
推荐答案
虽然MSVC绝对不是POSIX兼容,错误号
在MSVC运行时实现(至少为MSVC2008)的线程安全的方式。
Although MSVC is definitely not POSIX compliant, errno
is implemented in the MSVC runtime (at least as of MSVC2008) in a threadsafe manner.
虽然文档指出这是的extern INT错误号
它是作为一个的#define
实际实现的一个功能,允许线程安全的罚款。如果你通过反汇编窗口此功能一步到位,很显然,线程本地存储被使用。
Although the documentation states that it is extern int errno
it's actually implemented as a #define
to a function which allows thread-safety to be imposed. If you step through this function in the disassembly window, it is clear that thread local storage is used.
不幸的是,我不能指向证实了这一点任何正式文件,但生活就是这样!
Sadly I can't point to any official documentation that confirms this but such is life!
这篇关于MSVC的errno线程安全的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!