On Wed, 26 Aug 2026 at 18:06, Pali Rohár <[email protected]> wrote:

> On Wednesday 26 August 2026 10:53:28 LIU Hao wrote:
> > 在 2026-8-23 20:21, Pali Rohár 写道:
> > > diff --git a/mingw-w64-crt/misc/_beginthreadex.c
> b/mingw-w64-crt/misc/_beginthreadex.c
> > > new file mode 100644
> > > index 000000000000..dad6eccf97ff
> > > --- /dev/null
> > > +++ b/mingw-w64-crt/misc/_beginthreadex.c
> > > +  if (thread_handle != (uintptr_t)-1) {
> > > +    /* Set HANDLE_FLAG_INHERIT and DACL_SECURITY_INFORMATION as soon
> as possible. */
> > > +    if (inherit_handle)
> > > +      SetHandleInformation((HANDLE)thread_handle,
> HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT);
> > > +    if (dacl_descriptor)
> > > +      SetKernelObjectSecurity((HANDLE)thread_handle,
> DACL_SECURITY_INFORMATION, dacl_descriptor);
> > > +
> > > +    /* Wait until the child thread_func started, filled the
> thread_id_ptr,
> > > +     * stopped using our stack variables, including the automatic
> array of
> > > +     * arguments OR the newly spawned child thread crashed/finished.
> >
> > This could cause a deadlock if `_beginthreadex` is called inside
> `DllMain()`.
>
> Ah... that is right. Thread spawned in DllMain does not start its entry
> point until the DllMain finishes.


Been a while since I looked at win32 stuff but correct me if I'm wrong but
wouldn't
it be better to just pass those variables to DllMain to make use of
instead? They
don't need to be passed to _beginthreadex/_endthreadex after all, they just
need
to be passed to DllMain to avoid race conditions and needless locking of
mutices,
semaphores, etc

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

Reply via email to