gpt4 book ai didi

c - 为什么以及在何种意义上 pthread_t 是不透明类型?

转载 作者:太空宇宙 更新时间:2023-11-04 00:47:12 31 4
gpt4 key购买 nike

SO 上的帖子表明 pthread_t 是不透明类型,不是数字,当然也不是线程索引,你不应该直接比较 pthread_t 的,等等等等

问题:

  1. 为什么?是否真的有意支持没有线程数字 ID 的系统?当 pthread_t 实现只是

    typedef unsigned long int pthread_t;

    ?

  2. 如何?上面一行之前有注释,所以其实是

    /* Thread identifiers. The structure of the attribute type is not
    exposed on purpose. */
    typedef unsigned long int pthread_t;

    pthreadtypes.h 中是什么意思?什么属性类型?这不是某个全局线程表的索引吗?

最佳答案

POSIX 标准允许pthread_t 是更复杂的东西(例如结构)。 See this previous question ,尤其是@james-mcnellis 的回答。货币报价:

IEEE Std 1003.1-2001/Cor 2-2004, item XBD/TC2/D6/26 is applied, adding pthread_t to the list of types that are not required to be arithmetic types, thus allowing pthread_t to be defined as a structure.

更新:这里有一些更复杂的 pthread_t 定义的例子:

这里是 Win32 的 pthreads 库中使用的 pthread_t 结构的古老(2007)证明:https://sourceware.org/ml/pthreads-win32/2007/msg00056.html

关于c - 为什么以及在何种意义上 pthread_t 是不透明类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33285562/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com