[libc-commits] [libc] [libc] Add an extension macro to get numerical thread id (PR #195202)

Alexey Samsonov via libc-commits libc-commits at lists.llvm.org
Fri May 1 09:18:35 PDT 2026


vonosmas wrote:

> > > This approach sounds good to me.
> > > However, I was wondering if we can just promise that thread id is semiregular object with unique object representation such that libc++ can simply use bytewise comparison instead of extending libc?
> > 
> > 
> > Well, libc++ needs to implement strong total ordering for [std::thread::id](https://en.cppreference.com/cpp/thread/thread/id) , and there's fair amount of assumptions in their code to assume that implementation-specific `__libcpp_thread_id` behaves like an integer (see [implementation](https://github.com/llvm/llvm-project/blob/70b2f06ab493e29bb5dcc627bd016714dd21405f/libcxx/include/__thread/id.h#L41)). Changing all that to bytewise lexicographical comparison (which I think is what you propose?) on all platforms would be painful...
> 
> I was thinking of dispatching with `is_pointer/is_integral`. But maybe that will require too many changes inside libcxx.

Do you mean adding logic in libc++ that would implement necessary comparisons based on `std::is_pointer<pthread_t>` / `std::is_integral<pthread_t>`? Yeah, that would require some changes to libc++, but that would also not help in our case, where `pthread_t` is a struct with a pointer field? And I think adding our own specialization for `is_pointer` is [UB](https://en.cppreference.com/cpp/types/is_pointer)?

https://github.com/llvm/llvm-project/pull/195202


More information about the libc-commits mailing list