zoukankan      html  css  js  c++  java
  • errno线程安全性

    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是线程局部的。

  • 相关阅读:
    原型1
    可参考的gulp资源
    手机端rem自适应布局实例
    页面变灰效果
    图片上传
    angular学习笔记
    远程页面调试
    drag
    真的了解JS么?
    发现意外之美
  • 原文地址:https://www.cnblogs.com/HachikoT/p/12129076.html
Copyright © 2011-2022 走看看