SO 上的帖子表明pthread_t
是一个不透明类型,不是数字,当然也不是线程索引,您不应该直接比较pthread_t
的等等等等
问题:
-
为什么?是否真的有意支持没有线程数字 ID 的系统?当。。。的时候pthread_t
实施很简单
typedef unsigned long int pthread_t;
?
-
如何?上面这行之前有一个注释,所以实际上是
/* Thread identifiers. The structure of the attribute type is not
exposed on purpose. */
typedef unsigned long int pthread_t;
in pthreadtypes.h
这意味着什么?什么属性类型?这不是某个全局线程表的索引吗?
POSIX 标准允许pthread_t
成为更复杂的东西(例如结构)。请参阅上一个问题,尤其是@james-mcnellis 的回答。金钱报价:
应用 IEEE Std 1003.1-2001/Cor 2-2004,项目 XBD/TC2/D6/26,添加
pthread_t 到不需要算术的类型列表
类型,从而允许将 pthread_t 定义为结构体。
UPDATE: 下面是一些更复杂的例子pthread_t
定义:
- https://github.com/JoakimSoderberg/pthreads-win32/blob/master/pthread.h
- http://www.mit.edu/afs.new/sipb/project/pthreads/include/pthread.h
- http://svn.gna.org/svn/xenomai/trunk/include/posix/pthread.h
这是一个古老的(2007)理由pthread_t
Win32 的 pthreads 库中使用的结构:https://sourceware.org/ml/pthreads-win32/2007/msg00056.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)