On Tuesday 13 October 2026 14:50:55 LIU Hao wrote:
> I think I have found a bug in winpthreads:
> ...
> which gives
> 
>    ```
>    thread created
>    in DllMain: key = 0, str = DllMain
>    in thread_fn 1: key = 0, str = (null)
>    in thread_fn 2: key = 0, str = thread_fn
>    in tls_dtor: key = 0, str = thread_fn
>    thread joined
>    ```
> 
> The DLL calls `pthread_setspecific()`, which calls `__pthread_self_lite()`,
> which happens before `pthread_create_wrapper()` begins execution, so the
> current thread doesn't have a pthread structure yet. In this case
> `__pthread_self_lite()` allocates a blank structure and assigns a pointer to
> `_pthread_tls`, which is later overwritten by `pthread_create_wrapper()`.
> The previous structure leaks, along with the event handle, the thread
> handle, and all TLS keys.

Nice catch. The problem is that pthread_create_wrapper() expects that no
other code for the newly spawned thread was executed.

But this is not truth. Every native PE TLS callback is executed before.
And for DLL builds also DllMain is executed before.

Fixing this would need slightly larger changes...

> The Microsoft threads DLL doesn't seem to be affected; but linking their
> static CRT causes assertion failures when `tss_set()` is called from
> `DllMain()`.
> 
> 
> -- 
> Best regards,
> LIU Hao


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

Reply via email to