Prayer

在一般中寻求卓越
posts - 1256, comments - 190, trackbacks - 0, articles - 0
  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

AIX多线程编程与errno全局变量

Posted on 2009-05-08 15:58 Prayer 阅读(1177) 评论(0)  编辑 收藏 引用 所属分类: C/C++LINUX/UNIX/AIX
使用gcc -D_THREAD_SAFE,此时errno是每个线程相关的,不再是全局变量。当正确地
包含<errno.h>之后,errno被重新定义过:

#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.
 */
#define errno (*_Errno())

#endif

extern int errno;

函数_Errno()返回一个指针,指向一个线程相关整数。注意,你仍然可以使用&errno。

在/usr/include/*.h中grep查看一下,会发现如果指定了-D_THREAD_SAFE,就不必再
指定-D_REENTRANT以及-D_THREAD_SAFE_ERRNO。


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理