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

    在UNIX的多线程下用到errno的时候,要留意下了,否则无法得到正确的errno。
    在AIX下,编译的时候需要加入-D_THREAD_SAFE
    在solaris下,编译的时候需要加入 -D_REENTRANT
    在hp-ux下,编译的时候 需要加入  -D_REENTRANT
    在linux下,不存在任何问题,可以放心大胆的使用
    通过这个问题,还学到一招,查看include头文件,我想在某些时候会起到些作用。
    比如,查看AIX下的/usr/include/errno.h文件,会发现这样的声明:
    #if defined(_THREAD_SAFE) || defined(_THREAD_SAFE_ERRNO)
    /*
    * Per thread errno is provided by the threads provider. Both the extern int
    * and the per thread value must be maintained by the threads library.
    */
    extern   int      *_Errno( void );
    #define errno    (*_Errno())
    #else
    extern int errno;
    #endif   /* _THREAD_SAFE || _THREAD_SAFE_ERRNO */
    所以不言而喻了,需要加入_THREAD_SAFE 或者 _THREAD_SAFE_ERRNO
    然后查看solaris的/usr/include/errno.h就不是这两个宏了。
    联想有时候编译某些开源代码的时候,会报一些错误,说找不到某些函数,有可能就是某些宏没有定义,查一查相关的inclue文件,没准就编过去了。
  • 相关阅读:
    cpp 模版函数
    叉积
    利用scrollTop 制作图片无缝滚动
    事件绑定和时间取消
    闭包写法
    增加类,删除类,查找类
    获取元素到页面上的位置
    在IE8中如何通过javascripts改变<style />中的内容?
    有关app的一些小知识
    获取页面高宽知识
  • 原文地址:https://www.cnblogs.com/hbt19860104/p/2627104.html
Copyright © 2011-2022 走看看