Posted on 2009-05-08 15:58
Prayer 閱讀(1205)
評論(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。