[MPlayer-dev-eng] [PATCH] Windows GUI with mingw64 and cygwin revised part 2

Stephen Sheldon sfsheldo at gmail.com
Fri May 6 22:39:11 CEST 2011


 <emild <at> cs.technion.ac.il> writes:


> Sorry for the late comment, but is blindly replacing _beginthreadex() with
> CreateThread() a good idea? AFAIK programs which use the MS C runtime library
> should use _beginthreadex() instead of CreateThread() as the former does some
> thread-specific initialization. Using plain CreateThread() with the MS C
> runtime library can cause memory leaks. 
> 
> See also:
> 
> http://support.microsoft.com/kb/104641/en-us
> 
> > 
> > > Do it right away.
> > 
> > Committed.
> > 
> > Ingo
> 
>                                                            Regards,
>                                                                 Emil
Cygwin does not use the MS C runtime and indeed _beginthreadex is not
available when mplayer is linked under Cygwin.

Perhaps I should have used a compiler flag to call CreateThread,
like this

Index: interface.c
===================================================================
--- interface.c	(revision 33390)
+++ interface.c	(working copy)
@@ -22,6 +22,10 @@
  */
 
 #include <windows.h>
+#if !defined(__CYGWIN__)
+/* include for definition of _beginthreadex */
+#include <process.h>
+#endif
 #include "path.h"
 #include "gui/interface.h"
 #include "m_option.h"
@@ -493,7 +497,13 @@
     /* Create The gui thread */
     if (!mygui)
     {
+#if defined(__CYGWIN__)
+        /* _beginthreadex is not available in Cygwin */
         hThread = CreateThread(NULL, 0, GuiThread, NULL, 0, &threadId);
+#else
+	/* otherwise, use this function to work with the MS C runtime */
+        hThread = _beginthreadex(NULL, 0, GuiThread, NULL, 0, &threadId);
+#endif
         mp_msg(MSGT_GPLAYER, MSGL_V, "[GUI] Creating GUI Thread 0x%04x\n",
threadId);
     }
 







More information about the MPlayer-dev-eng mailing list