This is the mail archive of the mailing list for the pthreas-win32 project.

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

RE: Memory leak problem in MSVS6.0 C library when using pthread_creat e

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
taken place.

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.

-----Original Message-----
From: Mattias Ernelli []
Sent: December 22, 2000 4:00 AM
To: Pthreads Win32 (E-mail)
Subject: Memory leak problem in MSVS6.0 C library when using
pthread_creat e

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

Any clue?

Best regards,


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