This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Linking to cygwin1.dll and msvcrt.dll ?


On Wed, 18 Jul 2001, Corinna Vinschen wrote:

> I'm somehow missing a
> 
>        CloseHandle ((HANDLE)code);
> 
> at this point which at least closes the handle to the thread. Otherwise
> the following from MSDN is valid:
> 
>     The thread object remains in the system until the thread has
>     terminated and all handles to it have been closed through a
>     call to CloseHandle.
> 
> Corinna

That is interesting. The code variable is a local and the
pointer is not saved. Would this call to CloseHandle()
need to be done after a call to ExitThread()?

I guess I am not even sure why a call to _beginthreadex
is being made here instead of calling CreateThread.
The cvs log talks about a memory leak, perhaps this is
the leak Corinna has identified.

cheers
Mo

P.S.
Here is the patch I am currently playing with. This
is from the CVS version of Tcl at sourceforge.

Index: win/tclWinThrd.c
===================================================================
RCS file: /cvsroot/tcl/tcl/win/tclWinThrd.c,v
retrieving revision 1.12
diff -u -r1.12 tclWinThrd.c
--- win/tclWinThrd.c	2001/07/16 23:30:16	1.12
+++ win/tclWinThrd.c	2001/07/17 22:55:14
@@ -135,8 +135,15 @@
 
     EnterCriticalSection(&joinLock);
 
-    code = _beginthreadex(NULL, (unsigned) stackSize, proc, clientData, 0,
-	(unsigned *)idPtr);
+#ifdef __CYGWIN__
+    code = (unsigned long) CreateThread(NULL, (unsigned) stackSize,
+        (LPTHREAD_START_ROUTINE) proc, (LPVOID) clientData,
+        (DWORD) 0, (DWORD *)idPtr);
+#else
+    code = _beginthreadex(NULL, (unsigned) stackSize,
+        proc, (void *) clientData,
+        (unsigned) 0, (unsigned *)idPtr);
+#endif /* CYGWIN */
 
     if (code == 0) {
         LeaveCriticalSection(&joinLock);
@@ -202,7 +209,11 @@
     TclSignalExitThread (Tcl_GetCurrentThread (), status);
     LeaveCriticalSection(&joinLock);
 
+#ifdef __CYGWIN__
+    ExitThread((DWORD)status);
+#else
     _endthreadex((DWORD)status);
+#endif /* __CYGWIN__ */
 }
 
 

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]