<html><head></head><body>Hi,<br><br>Thanks for the review. I don't think the potential bug applies to plugins: Plugin module instances must already join their threads before they are destroyed. This should ensure that the thread code is already back from plugin code to LibVLC's vlc_entry(). So it is safe to unload plugins already now. If not, then I'd say that's a separate bug that I'll look at separately.<br><br>I have however noticed that this patch is wrong because it mismatches _beginthreadex() with ExitThread().<br><br>We have two alternatives, I think:<br>1) Switch to CreateThread() like you already did on Windows Store.<br>2) Assume that _endthreadex() calls FreeLibraryAndExitThread() internally (?) and drop this patch entirely.<br><br><div class="gmail_quote">Le 7 septembre 2020 08:51:13 GMT+03:00, Steve Lhomme <robux4@ycbcr.xyz> a écrit :<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<pre class="k9mail">On 2020-09-06 19:12, Rémi Denis-Courmont wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #729fcf; padding-left: 1ex;">Use FreeLibraryAndExitThread() instead of ExitThread() as Win32 does<br>not natively support non-detached threads. This fixes a race condition<br>when LibVLC is unloaded (see also MSDN on FreeLibraryAndExitThread()).<br></blockquote><br>That sounds better indeed.<br>It may be worth noting that it doesn't apply to DLLs from modules or <br>even libvlc, only the libvlccore DLL (where vlc_entry resides).<br><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #729fcf; padding-left: 1ex;"><hr>  src/win32/thread.c | 18 +++++++++++++-----<br>  1 file changed, 13 insertions(+), 5 deletions(-)<br><br>diff --git a/src/win32/thread.c b/src/win32/thread.c<br>index cd15828128..e7f2ee27d3 100644<br>--- a/src/win32/thread.c<br>+++ b/src/win32/thread.c<br>@@ -56,6 +56,7 @@ static DWORD thread_key;<br>  struct vlc_thread<br>  {<br>      HANDLE         id;<br>+    HMODULE        lib;<br>  <br>      bool           killable;<br>      atomic_bool    killed;<br>@@ -348,14 +349,12 @@ static void vlc_thread_destroy(vlc_thread_t th)<br>  <br>  static noreturn void vlc_thread_exit(vlc_thread_t self)<br>  {<br>+    HMODULE lib = self->lib;<br>+<br>      if (self->id == NULL) /* Detached thread */<br>          vlc_thread_destroy(self);<br>  <br>-#if VLC_WINSTORE_APP<br>-    ExitThread(0);<br>-#else // !VLC_WINSTORE_APP<br>-    _endthreadex(0);<br>-#endif // !VLC_WINSTORE_APP<br>+    FreeLibraryAndExitThread(lib, 0);<br>  }<br>  <br>  static<br>@@ -381,6 +380,14 @@ static int vlc_clone_attr (vlc_thread_t *p_handle, bool detached,<br>      struct vlc_thread *th = malloc (sizeof (*th));<br>      if (unlikely(th == NULL))<br>          return ENOMEM;<br>+<br>+    if (!GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,<br>+                           (const void *)vlc_entry, &th->lib))<br>+    {<br>+        free(th);<br>+        return ENOBUFS;<br>+    }<br>+<br>      th->entry = entry;<br>      th->data = data;<br>      th->killable = false; /* not until vlc_entry() ! */<br>@@ -402,6 +409,7 @@ static int vlc_clone_attr (vlc_thread_t *p_handle, bool detached,<br>      if (h == 0)<br>      {<br>          int err = errno;<br>+        FreeLibrary(th->lib);<br>          free (th);<br>          return err;<br>      }<br>-- <br>2.28.0<hr>vlc-devel mailing list<br>To unsubscribe or modify your subscription options:<br><a href="https://mailman.videolan.org/listinfo/vlc-devel">https://mailman.videolan.org/listinfo/vlc-devel</a><br><br></blockquote><hr>vlc-devel mailing list<br>To unsubscribe or modify your subscription options:<br><a href="https://mailman.videolan.org/listinfo/vlc-devel">https://mailman.videolan.org/listinfo/vlc-devel</a></pre></blockquote></div><br>-- <br>Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser ma brièveté.</body></html>