This is the mail archive of the
mailing list for the pthreas-win32 project.
Possible memory leak in Pthreads-Win32
- From: Jason Jones <jasonaptech at gmail dot com>
- To: pthreads-win32 at sourceware dot org
- Date: Thu, 1 Dec 2011 18:11:42 -0800
- Subject: Possible memory leak in Pthreads-Win32
I am having memory leaks when using Pthreads-Win32. I have attached a
very simple example program that illustrates the problem. It is very
1) Inside a for loop, I create two threads with pthread_create.
2) Each of these threads executes a function that just returns 0;
3) I print out the return from the pthread_create calls.
4) Then use pthread_join on the two threads and the execute the next
iteration of the loop.
As I run this program, I can watch the memory constantly growing (
through task manager ). If I let it run long enough, I have seen it
use 600 megabytes of memory. If I run the same program on Linux with
native pthreads, I do not see any memory growth no matter how long I
let it run. On Windows I see the memory leak with Visual Studio 2008
and also with the latest version of the Intel compiler.
Is this a memory leak? Or am I doing something stupid?
/********* COMPILE/LINK LINE **********************/
/*** cl -I./pthreads.2 pthread_leak.c pthreads.2/pthreadVC2.lib ******/
/*** icl pthread_leak.c -I./pthreads.2 pthread_grandchild.c pthreads.2/pthreadVC2.lib ******/
int *call_print(void *ptr);
pthread_t thread1, thread2;
char *message1 = "1";
char *message2 = "2";
int iret1, iret2, i;
/* Create independent threads each of which will execute function */
iret1 = pthread_create( &thread1, NULL, call_print, (void*) message1);
iret2 = pthread_create( &thread2, NULL, call_print, (void*) message2);
printf("Thread 1 returns: %d iteration: %d\n",(int)iret1,(int)i);
printf("Thread 2 returns: %d\n",(int)iret2);
pthread_join( thread1, NULL);
pthread_join( thread2, NULL);
int *call_print(void *ptr)