Martin Storsjö <[email protected]> wrote:

> On Tue, 6 Oct 2026, Kirill Makurin wrote:
>> Implementing C11 threads support around winpthreads is surely an option. 
>> OTOH, C11 threads look pretty minimalistic:
>>
>> 1. Threads (thrd_t)
>> 2. Mutexes (mtx_t)
>> 3. Once (once_flag)
>> 4. Conditional variables (cnd_t)
>>
>> I think it would be better to implement them directly around Windows
>> APIs, is a separate library. We could reuse code from winpthreads
>> though.
>
> Yes, I agree. I think that toolchains linking in winpthreads as a default
> library is becoming less common, so for them, requiring winpthreads for
> C11 threads sounds suboptimal.

This also a good argument against implementing C11 threads around winpthreads.

One benefit of winpthreads is that me and Pali trying to make it work on old 
Windows versions, so users can produce binaries for those Windows versions. 
Regardless, I think that toolchains switching to better alternatives (e.g. gcc 
using native Windows TLS by default) is a good thing for majority of the users; 
those who need support for older systems can configure the toolchain 
appropriately.

> As for the other points made earlier - I'm not sure that we need to have
> them ABI compatible with MSVC's version - probably not. If we can it would
> be nice though.

Yes, this would be nice. One potential issue is MSVC changing its ABI at some 
point in future. However, given that there were only a few ABI changes in 
public CRT functions, I think chances of this are pretty low.

> Likewise, I think don't think that it's strictly necessary to have the
> code in a separate DLL at all. Users diskike extra runtime DLLs.

This a good point. I wish we could give users a choice, with static being the 
default. I think it would be really nice if we could handle it in a way similar 
to -static-libgcc and -shared-libgcc options.

Would it be possible for use to first add such a library, and then introduce a 
compiler option for using it?

> Are we
> sure the implementation needs any shared state? And even if needed, I
> think it would be rare to have C11 threads.h types used across DLL
> boundaries.

One such case would be functions like `pthread_self`, or in case of C11 
threads, it would be `thrd_current`. For example, if EXE creates a thread and 
then DLL calls `thrd_current` from that thread, there will be two `thrd_t` 
object for the same thread.

Such cases are an example why I think using winpthreads as a DLL should always 
be preferred.

> (And given https://github.com/skeeto/w64devkit/blob/master/src/threads.c
> it seems like an implementation can be very slim - at least as long as one
> doesn't implement all the details of the API.)

- Kirill Makurin

_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to