在 2026-7-3 03:28, Martin Storsjö 写道:
On Wed, 1 Jul 2026, LIU Hao wrote:

From 1ba9bec1ea24f9c4863f9dc2e8068b32fb4fdd8a Mon Sep 17 00:00:00 2001
From: LIU Hao <[email protected]>
Date: Wed, 1 Jul 2026 17:32:00 +0800
Subject: [PATCH] crt,winpthreads: Do not run any user-defined destructors in
TLS callbacks upon process termination

These callbacks are called after `ExitProcess()` is called, after all atexit
callbacks are called. So first, standard C++ requires that destructors of
thread-local objects be called before destructors of static objects, and POSIX
doesn't say that destructors to `pthread_key_create()` should be called upon
process exit. Either way, this isn't the correct opportunity to run thread-local
destructors.

Second, TLS callbacks (as well as `DllMain()`) are called after the system
terminates all the other threads in indeterminate states. If another thread has
locked a mutex when it is terminated, there's no chance for it to unlock the
mutex. If the current thread attempts to lock such a mutex, it will have to wait
forever, resulting in a deadlock.

Reference: https://devblogs.microsoft.com/oldnewthing/20100122-00/?p=15193
Signed-off-by: LIU Hao <[email protected]>
---
mingw-w64-crt/crt/crtdll.c                   |  3 ++-
mingw-w64-crt/crt/tls_atexit.c               | 25 +++++++++++---------
mingw-w64-crt/crt/tlsthrd.c                  |  5 ++--
mingw-w64-libraries/winpthreads/src/thread.c |  3 ++-
4 files changed, 21 insertions(+), 15 deletions(-)

Thanks, I think this patch seems ok.


Thanks, pushed now, with the commit message amended a little.



--
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