MSVC的errno线程安全 [英] MSVC errno thread safety

查看:203
本文介绍了MSVC的errno线程安全的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

错误号上MSVC线程安全的?

Is errno on MSVC thread-safe?

根据这个问题 POSIX要求错误号是线程安全的。但是MSVC大概POSIX不兼容和 MSDN 不告诉线程安全的东西。 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线程安全的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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