I am reviewing code using POSIX threads and running on Linux platform using older LinuxThreads implementatation of POSIX threads (cross-compiled code, target MIPS/uClibc if it makes any difference). If there is any difference in the answer for NPTL implementation, I would like to know that too for completeness sake. The question concerns about type pthread_t which I can see from the C library header files to be defined as unsigned long int for both uClibc and glibc (Embedded GNU C library actually – I only have Ubuntu available as reference).

To the question... A variable of type pthread_t is used to store the owner of a property. What bothers me is that I see assignment of 0 to mark that no thread owns that property; it bothers me because I know POSIX standard states that pthread_t type is opaque and we should not make any assumptions about the type. I know that it would be better to e.g. use a boolean flag to determine if the property is owned by a thread. I do hold the opinion the code should be fixed to respect the POSIX standard in the longer run (if not for other reasons then for saving the future generations from pondering the robustness of the code), but now for short term I need to know the answer to the following question: can we assume that pthread_t value of 0 can never be set by pthread_create(3) in this platform (the only way we should get a pthread_t value as far as I know), and subsequently: is the assignment to value 0 a robust way to mark the property unused in this platform?

0

There are 0 answers