在 2026-7-6 18:13, Martin Storsjö 写道:

This might be acceptable.

It might be worth clarifying the commit message further that "win32 thread model" specifically refers to libgcc (and implicitly through libgcc also libstdc++); this code isn't used by other codepaths.

I will fix that.


I'm not entirely convinced that this is the right thing to do in general - I think this would lead to destructors not being executed in cases where I think they would be executed in e.g. an MSVC build.

Does this cause e.g. destructors for user code TLS C++ objects in DLLs to not be executed on process exit, for builds using libstdc++/libgcc?

No. Destructors of thread-local objects are registered with `__cxa_thread_atexit()` which is implemented in cxa_thread_atexit.c.

However, this change has an effect on emutls, so memory for thread-local objects is no longer freed upon process exit. This might look harmless; but frankly speaking, I didn't test it.


This should at least affect fewer cases than the previous patch.

But overall, the problem is the same - destructors in DLLs on process exist, when threads still may be running, really are tricky on Windows in general. I think the conventional method is to fix this on the user code side - but there's usually no single easy way of fixing it.

TL;DR - this patch shouldn't hurt me and my configurations I think, so I won't block it, but I think it's principally slightly wrong.

`__mingwthr_key_dtor()` is called internally by `__gthread_key_create()` for win32 thread model [1]. In the case of posix thread model, `pthread_key_create()` is called instead. My conclusion is that these two variants should behave identically.

Interestingly, while `pthread_key_create()` says nothing about process termination [2], the C11 `tss_create()` requires that '[d]estructors associated with thread-specific storage shall not be invoked at process termination.' [3]


[1] https://github.com/gnutools/gcc/blob/ca97c747850478628fcdd25b747fe2f8bc725738/libgcc/config/i386/gthr-win32.h#L684
[2] 
https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_key_create.html
[3] https://pubs.opengroup.org/onlinepubs/9799919799/functions/tss_create.html


--
Best regards,
LIU Hao

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature

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

Reply via email to