在 2024-12-05 20:38, Martin Storsjö 写道:
When the libstdc++/libsupc++ implementation of __cxa_thread_atexit is
used in conjunction with emulated TLS, both emutls and libsupc++
register destructors to be executed via pthread_key_create; one for
freeing the per-thread memory allocated for the TLS objects, and
one for executing the destructors. They are registered in a sequential
order; first emutls registers the destructor for freeing the memory,
followed by libsupc++ registers a destructor for running the TLS
                       ^ 'which' registers a destructor ...

object destructors.

Therefore, running the pthread key destructors in reverse order makes
sure that the TLS object destructors are called (via libsupc++) before
their memory is deallocated (via emutls).

This pattern also matches how destructors normally are executed - in
opposite order compared with how they were constructors.
---
This part of the fix should at least work the same regardless of
whether winpthreads is in a separate DLL or statically linked into
the end user executable.
---
  mingw-w64-libraries/winpthreads/src/thread.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)

This idea sounds correct to me.

Technically, memory that is allocated by emutls should always be the last cleanup before a thread terminates. With winpthreads I don't see how it can be implemented.



--
Best regards,
LIU Hao

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature

_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to