On Wednesday 07 October 2026 08:45:57 Kirill Makurin wrote:
> LIU Hao wrote:
> 
> > 在 2026-10-7 15:54, Kirill Makurin 写道:
> >> Martin Storsjö <[email protected]> wrote:
> >>> 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.
> >
> > Despite C11 threading being introduced in Visual Studio 2022 version 
> > 17.8.0, the DLL name
> > `vcruntime140_threads.dll` still suggests Visual Studio 2015 where UCRT was 
> > introduced, which seems a
> > subtle hint about ABI compatibility.
> 
> Yes.

I think that to prevent aby interop issues, the best would be to follow
MSVC ABI. Mostly the mingw-w64 runtime uses MSVC ABI with compatible
header files for UCRT and msvcrt which guarantees that functions can be
called cross DLL boundaries (even when DLLs are compiled by different
versions of gcc or even different compilers and runtimes).

> >> 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.
> >
> > The Microsoft `thrd_t` is a structure of two fields: the handle is for 
> > `thrd_join()`, and the numeric
> > identifier is for `thrd_equal()`. But there still be issue if 
> > `thrd_detach(thrd_current())` is called.
> 
> Maybe following MSVC ABI is not the best idea after all...

vcruntime140_threads.dll implementation does support 
thrd_detach(thrd_current()).

thrd_current() returns NULL handle with the correct thread id.

But it does not mean that there cannot be other thrd_detach()
implementation which will use same above memory/struct ABI but will
implement thrd_detach() differently to support also thrd_current().

> > In mcfgthread, the TLS index for `TlsGetValue()` is stored in named shared 
> > memory, so all instances of
> > the library in the same process get the same value, no matter whether they 
> > are linked statically or
> > dynamically.
> 
> This sounds like a good solution. I think we should do the same in 
> winpthreads eventually.

Sure, this sounds like a good idea. I did not think about such trick.


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

Reply via email to