This is the mail archive of the
mailing list for the pthreas-win32 project.
RE: Memory leak problem in MSVS6.0 C RTL
- To: "'Bossom, John'" <John dot Bossom at Cognos dot COM>
- Subject: RE: Memory leak problem in MSVS6.0 C RTL
- From: Mattias Ernelli <Mattias dot Ernelli at melody dot se>
- Date: Fri, 22 Dec 2000 16:28:12 +0100
- Cc: "Pthreads Win32 (E-mail)" <pthreads-win32 at sourceware dot cygnus dot com>
Thanks for your quick reply.
I noticed what caused the problem when I link pthreads with my application.
I specify statically linked C RTL (libcmt/libcmtd) instead of dynamically
What happends is that the C RTL routines that uses the C RTL local storage
allocates data on the fly, for example when accessing errno or rand(). The C
RTL designers probably ensured that code calling CreateThread instead of
_beginthreadex should not break.
If I build my application using dynamically linked C RTL, the memory leak
goes away, probably because the RTL code that pthread calls to initialise
the RTL thread data is different from the statically linked RTL functions
that my application calls, and additionally data is allocated by the
statically linked C RTL code.
My question is then:
Is it possible to build the pthread-win32 library for statically linking?
Booth regarding the linkage specification for the C RTL as well as
The reason for using statically linked libraries is in general that our
application consists mainly of separate modules, each as a static library,
each compiled using a static linkage specification for the C RTL, we could
switch to dynamically linked C RTL, but I would prefer statically linked
code. Its easier to keep things together and to avoid "dll hell"...
From: Bossom, John [mailto:John.Bossom@Cognos.COM]
Sent: den 22 december 2000 13:56
To: 'Mattias Ernelli'; Pthreads Win32 (E-mail)
Subject: RE: Memory leak problem in MSVS6.0 C library when using
pthread_c reat 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
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.