On Mon, 6 Jul 2026, LIU Hao wrote:

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

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.

Oh, intresting. There are other known problems with C++ TLS dtors and emutls freeing the memory as well - although I don't remember if that was at thread exit, DLL unload or process exit though, so I guess this also would avoid some aspects of that problem too.

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.

Does this hold for pthread_key_create right now, that the callbacks aren't called on process exit? Then that's a good argument for this change.

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]

Interesting - I guess that's even more arguments for this change then.

// Martin

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

Reply via email to