[Development] thread_local: replacing GCC with Clang for MinGW

Olivier Goffart olivier at woboq.com
Mon Aug 26 09:42:52 CEST 2019


On 25.08.19 17:43, Thiago Macieira wrote:
> On Sunday, 25 August 2019 00:44:51 PDT Olivier Goffart wrote:
>> One could fix the leak by re-implementing DllMain in QtCore and using the
>> DLL_THREAD_DETACH hook to delete the QAdoptedThread
>> https://docs.microsoft.com/en-us/windows/win32/dlls/dllmain
>>
>> That would fix the leak for dynamic Qt build.
>>
>> But for static build we would need another trick.
>> The comments from this file are pretty interesting and would provide a
>> solution:
>> https://github.com/rust-lang/rust/blob/master/src/libstd/sys/windows/thread
>> _local.rs#L130
> 
> I'm not interested in further adding workarounds for compiler shortcomings
> that may be fixed in the very next release of those compilers when we already
> have a working solution.

Fair enough.
I was just saying how to workaround the problem, should anyone want to fix it.

> People using std::thread are unlikely to be using QThreadStorage. If they have
> a problem with thread_local and want to use QThreadStorage, they can change
> the thread start too.

This is not only about QThreadStorage. The QAdoptedThread is leaking as well. 
So any use of Qt API that uses QObject (e.g: creating a QFile or a QTextStream 
on the stack) will be leaking some memory if it is not done in a QThread.
(I did not know about this leak before reading your earlier message. I thought 
we had cleanup in place like for Unix. But I verified and indeed, it seems that 
we do not have thread cleanup in place for Windows)




More information about the Development mailing list