[PATCH] pthread: add PTHREAD_NULL
Carlos O'Donell
carlos@redhat.com
Mon Nov 3 14:10:25 GMT 2025
On 11/1/25 5:51 PM, Collin Funk wrote:
> Hi Alyssa,
>
> Alyssa Ross <hi@alyssa.is> writes:
>
>> New in POSIX.1-2024.
>>
>> In htl, pthread_t values are integers starting at 1, so 0 is a safe
>> null value.
>>
>> In nptl, pthread_t values are non-null pointers, so 0 is a safe null
>> value.
>> ---
>> I wasn't sure whether this should be behind a __USE macro, but there
>> isn't one for POSIX.1-2024 yet:
>> https://inbox.sourceware.org/libc-alpha/d34488044ace7c01311fb1c1948e65a050e93252.1747972803.git.collin.funk1@gmail.com/
>>
>> manual/threads.texi | 5 +++++
>> sysdeps/htl/pthread.h | 2 ++
>> sysdeps/nptl/pthread.h | 3 +++
>> 3 files changed, 10 insertions(+)
>>
>> diff --git a/manual/threads.texi b/manual/threads.texi
>> index 1e9be32d66..d3692e8939 100644
>> --- a/manual/threads.texi
>> +++ b/manual/threads.texi
>> @@ -1099,6 +1099,11 @@ This function gets the kind of mutex @var{mutex} is.
>> @node POSIX Threads Other APIs
>> @subsection POSIX Threads Other APIs
>>
>> +@deftypevr Macro pthread_t PTHREAD_NULL
>> +@standards{POSIX.1-2024, pthread.h}
>> +A value for pthread_t that is not considered equal to any thread ID.
>> +@end deftypevr
>> +
>> @deftypefun int pthread_equal (pthread_t @var{thread1}, pthread_t @var{thread2})
>> Compares two thread IDs. If they are the same, returns nonzero, else returns zero.
>> @manpagefunctionstub{pthread_equal, 3}
>> diff --git a/sysdeps/htl/pthread.h b/sysdeps/htl/pthread.h
>> index a299fec278..d490f3cdf8 100644
>> --- a/sysdeps/htl/pthread.h
>> +++ b/sysdeps/htl/pthread.h
>> @@ -55,6 +55,8 @@ __BEGIN_DECLS
>>
>> #include <bits/pthread.h>
>>
>> +#define PTHREAD_NULL ((pthread_t)0)
>> +
>> /* Possible values for the process shared attribute. */
>> #define PTHREAD_PROCESS_PRIVATE __PTHREAD_PROCESS_PRIVATE
>> #define PTHREAD_PROCESS_SHARED __PTHREAD_PROCESS_SHARED
>> diff --git a/sysdeps/nptl/pthread.h b/sysdeps/nptl/pthread.h
>> index 92957a620d..b47b732a9f 100644
>> --- a/sysdeps/nptl/pthread.h
>> +++ b/sysdeps/nptl/pthread.h
>> @@ -33,6 +33,9 @@
>> # include <bits/pthread_stack_min-dynamic.h>
>> #endif
>>
>> +#define PTHREAD_NULL ((pthread_t)0)
>> +
>> +
>> /* Detach state. */
>> enum
>> {
>>
>> base-commit: 720e89163702ffa1e921d926b6c36b53c3ccbee4
>
> I don't think this will cause conform tests to fail since PTHREAD_* is
> allowed. But it should probably be hidden under __USE_XOPEN2K24 which is
> not yet introduced. I have an old patch that is still waiting on review
> [1].
That's stuck in my queue for review and I haven't gotten to it yet,
but I agree it should likely go under some conditional e.g. __USE_XOPEN2K24.
I should finish the review for you for the additional constants. Let me see
if I can get that off my plate.
> Collin
>
> [1] https://inbox.sourceware.org/libc-alpha/d34488044ace7c01311fb1c1948e65a050e93252.1747972803.git.collin.funk1@gmail.com/
>
--
Cheers,
Carlos.
More information about the Libc-alpha
mailing list