Why and in what sense is pthread_t an opaque type?

后端 未结 2 1116
情书的邮戳
情书的邮戳 2021-01-19 10:12

Posts here on SO suggest that pthread_t is an opaque type, not a number, certainly not a thread index, that you shouldn\'t directly compare pthread_t

2条回答
  •  既然无缘
    2021-01-19 10:55

    The POSIX standard allows pthread_t to be something more complex (such as a structure). See this previous question, especially the answer by @james-mcnellis. Money quote:

    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.

    UPDATE: Here are a few examples of more complex pthread_t definitions:

    • 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

    And here is an ancient (2007) justification of the pthread_t structure used in the pthreads library for Win32: https://sourceware.org/ml/pthreads-win32/2007/msg00056.html

提交回复
热议问题