This is the mail archive of the
mailing list for the pthreas-win32 project.
RE: Memory leak problem in MSVS6.0 C library when using pthread_creat e
- To: 'Mattias Ernelli' <Mattias dot Ernelli at melody dot se>, "Pthreads Win32 (E-mail)" <pthreads-win32 at sourceware dot cygnus dot com>
- Subject: RE: Memory leak problem in MSVS6.0 C library when using pthread_creat e
- From: "Bossom, John" <John dot Bossom at Cognos dot COM>
- Date: Fri, 22 Dec 2000 07:56:16 -0500
The code should be using beginthreadex and endthreadex... These
interfaces ensure that the C RTL is initialized and cleaned up properly.
If you do not use these thread routines and you attempt a C RTL call,
you will probably blow up since C RTL initialization will not have
Now, the implementation of TSD for pthreads requires that you use the
DLL version of pthreads... If you check the DllMain, you will see
that it should, if DLL_THREAD_DETACH is passed, cause the TSD destroy
routines to be called for this terminating thread, on all thread keys
that have a destroy routine.
If you are using the static link library for pthreads, you will have to
perform this cleanup yourself.
From: Mattias Ernelli [mailto:Mattias.Ernelli@melody.se]
Sent: December 22, 2000 4:00 AM
To: Pthreads Win32 (E-mail)
Subject: Memory leak problem in MSVS6.0 C library when using
I have encountered a memory leak problem when using pthreads for Win32.
The leak occurs in the Microsfoft MSVS 6.0 C library. The problem is that
the native Win32 Threads API did not provide a method to install cleanup
handlers for the thread like pthread does when using pthread_key_create for
Thus the C library shipped with MSVS 6.0 for Win32 requires that all threads
that uses the C library is created using the library functions beginthread
or beginthreadex, so that memory used for the thread specific C runtime data
can be allocated/deallocated automatically. This data is used for internal
structures used by libc as well as errno, randseed etc.
Now I have discovered when running applications using pthreads through
purify that each terminating thread leaves a memory leak of the C library
thread specific data on the heap.
After examining the source code in pthread_create I noticed that a call to
beginthread is actually made, to ensure that endthread is properly called so
that the thread specific memory allocation made by the C library is freed,
but it doesnt in some strange way work that way. Actually, by the way the
leak appears it seems as if beginthreadex is not called at all.
Now since the source in pthread indicates that the C library memory
allocation is considered, otherwise a call to CreateThread could be issued
directly instead, I do belive that I am doing something wrong when
I have tried using the latest, 2000-09-08 pthreads-win32 but the problem