> On 5. Dec 2024, at 14.38, Martin Storsjö <mar...@martin.st> wrote:
> 
> Within winpthreads, a native posix thread is a thread that has
> been created via pthread_create.
> 
> Previously, pthread key destructors were executed immediately when
> the thread exits, for native posix threads. For non-posix native
> threads (i.e. threads created via some other API than pthreads),
> the pthread key destructors were executed later, via the
> __dyn_tls_pthread callback.
> 
> When a thread has got TLS objects, where the TLS implementation is
> provided via emutls (compiled with the GCC posix thread model, which
> uses winpthreads), the memory for those TLS objects is allocated
> via emutls and gets deallocated via a pthread key destructor.
> 
> When the destructors of the TLS objects are executed via
> mingw-w64-crt's __cxa_thread_atexit, those destructors are executed
> via a TLS callback, after the point when emutls has deallocated
> their storage memory.
> 
> To fix this, don't run the pthread key destructors immediately,
> but later via the __dyn_tls_pthread callback, just like for non-posix
> native threads. This makes sure the memory for the TLS objects isn't
> freed at the time when the destructors are executed.
> 
> See also: https://bugreports.qt.io/browse/QTBUG-131476

Also see https://bugreports.qt.io/browse/QTBUG-131892 for more discussion on 
the same, which also contains a direct request about whether we can try to fix 
winpthreads for this issue.

// Martin




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

Reply via email to