[clang] [Clang][Driver] Declare win32 threads on Windows (PR #121442)
Martin Storsjö via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 1 14:44:57 PST 2025
mstorsjo wrote:
As background for other reviewers: GCC can be built with either the posix or win32 thread model. This doesn't affect code generation much (at all?), but it does affect libgcc and libstdc++ which are built in the same GCC build.
With the win32 thread model, libgcc/libstdc++ use win32 thread/synchronization functions directly. With the posix thread model, libgcc/libstdc++ use regular pthread calls, via the separate winpthreads library. Thus, if using the posix thread model, everything has a dependency on winpthreads.
It used to be the case that the win32 thread abstraction in libgcc didn't suffice for C++11 threads, so in win32 thread model, you wouldn't have working C++11 threads. And conversely, people would assume that pthreads and the posix thread model are required for working C++11 threads. When using libc++ instead of libstdc++, this doesn't make any difference though, libc++ defaults to working C++11 threads by using win32 thread functions directly (disconnected from any thread model setting). And if one really wants to, one can build libc++ on Windows using pthread APIs via the same winpthreads library as well...
Since the last 1-2 major releases of GCC, this is no longer the case, the win32 thread model has been improved, so they should mostly have feature parity these days. But many people run `gcc -v` to check the thread model, and do assumptions based on this.
This then follows on to Clang - people look at `clang -v` to inspect the thread model, assuming either that it means that everything ends up requiring winpthreads, and/or something else.
Overall, I'm not entirely sure that this (this PR) is the way we want to go, though. Sure, people are misinformed and make incorrect conclusions, but I'm not sure if we should complicate it further either. (I faintly remember some recent discussion about the concept of thread model in clang, and I think someone mentioned that perhaps we should stop printing this altogether? But I can't find that reference right now.)
https://github.com/llvm/llvm-project/pull/121442
More information about the cfe-commits
mailing list