[libc-commits] [libc] [libc] Add an extension macro to get numerical thread id (PR #195202)
Petr Hosek via libc-commits
libc-commits at lists.llvm.org
Tue May 5 14:03:17 PDT 2026
petrhosek wrote:
I believe the underlying issue is the mismatch between C standard library and C++ standard library API. I'm going to ignore pthreads and focus on C11 threads for simplicity, but it applies to both. In the C standard library, `thrd_t` is an implementation-defined opaque object representing a thread; there's no separate notion of thread ID. In the C++ standard library, there's [`std::thread`](https://en.cppreference.com/cpp/thread/thread) but also [`std::thread::id`](https://en.cppreference.com/cpp/thread/thread/id). In libc++ implementation, `std::thread` is backed by [`__libcpp_thread_t` which maps to `thrd_t`](https://github.com/vonosmas/llvm-project/blob/3e10839a6bb63e1539b1a5632f7b5675a44121e7/libcxx/include/__thread/support/c11.h#L132) and `std::thread::id` is backed by [`__libcpp_thread_id` which also maps to `thrd_t`](https://github.com/vonosmas/llvm-project/blob/3e10839a6bb63e1539b1a5632f7b5675a44121e7/libcxx/include/__thread/support/c11.h#L125). The latter mapping is an issue because `std::thread::id` is defined to be trivially copyable and comparable which `thrd_t` is not. This change is effectively introducing the C counterpart to `std::thread::id` as a non-standard extension to address the mismatch.
https://github.com/llvm/llvm-project/pull/195202
More information about the libc-commits
mailing list