首页 > 编程语言 > 详细

errno线程安全性

时间:2020-01-01 16:49:48      阅读:67      评论:0      收藏:0      [点我收藏+]

errno

errno用于获取系统最后一次出错的错误代码。在C++中,errno其实是宏

// windows
#define errno (*_errno())

// linux
#define errno (*__errno_location ())

errno是线程安全的

在C++98中虽然没有规定这一点,但具体实现中基本都是线程安全的,POSIX.1c就规定errno是线程局部的,比如linux中对errno的定义为(注意这里#不是注释而是将预处理命令分开了):

# ifndef __ASSEMBLER__
/* Function to get address of global `errno' variable.  */
extern int *__errno_location (void) __THROW __attribute__ ((__const__));

#  if !defined _LIBC || defined _LIBC_REENTRANT
/* When using threads, errno is a per-thread value.  */
#   define errno (*__errno_location ())
#  endif
# endif /* !__ASSEMBLER__ */
#endif /* _ERRNO_H */

在C++11标准中规定了errno是线程局部的。

errno线程安全性

原文:https://www.cnblogs.com/HachikoT/p/12129076.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!