public inbox for pthreads-win32@sourceware.org
 help / color / mirror / Atom feed
* Possible memory leak in Pthreads-Win32
@ 2011-12-02  2:11 Jason Jones
  2011-12-02 14:10 ` Ross Johnson
  0 siblings, 1 reply; 2+ messages in thread
From: Jason Jones @ 2011-12-02  2:11 UTC (permalink / raw)
  To: pthreads-win32

[-- Attachment #1: Type: text/plain, Size: 906 bytes --]

Hello!

I am having memory leaks when using Pthreads-Win32. I have attached a
very simple example program that illustrates the problem. It is very
simple:

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?

Thanks,

Jason

[-- Attachment #2: pthread_leak.c --]
[-- Type: text/x-csrc, Size: 946 bytes --]

#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
/********* 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);
 
int main()
{
  pthread_t thread1, thread2;
  char *message1 = "1";
  char *message2 = "2";
  int  iret1, iret2, i;
 
 /* Create independent threads each of which will execute function */

   for(i=0;i<4000000;i++)
   { 
     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);

   }
   return 0;
}

int *call_print(void *ptr)
{
    return 0;
}
 

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Possible memory leak in Pthreads-Win32
  2011-12-02  2:11 Possible memory leak in Pthreads-Win32 Jason Jones
@ 2011-12-02 14:10 ` Ross Johnson
  0 siblings, 0 replies; 2+ messages in thread
From: Ross Johnson @ 2011-12-02 14:10 UTC (permalink / raw)
  To: Jason Jones; +Cc: pthreads-win32

Hi Jason,

I ran your test with the pthreadVC2.dll that I've just built from the 
sources from the current cvs head and did not see any resources growing 
over time, including memory, handles, etc. Peak working set was about 
1.6MB and Working Set (Private) was about 550kB toggling between a max 
and min value with small delta but not growing at all.

The particulars for this test were:

- current cvs head revision of the code
- Windows Vista 32 bit
- MSVS 2010 Express compiler (32 bit)
- pthreadVC2.dll built by runing "nmake clean VC-inlined"
- test suite passed by running "nmake clean VC" in the tests folder
- your test compiled by running "nmake pthread_leak-1.exe" in the tests 
folder (only succeeds if run after running the test suite so that the 
required headers and libs are copied into the tests folder).

I also compiled your test using the command line in your comments 
(modified to run relative to the tests folder), i.e. without all the 
additional flags from the nmake build, and no leak there either but did 
consume slightly more memory.

You didn't indicate what version of the library you are using (pre-built 
or built from source) or any other details of your system but I'm 
reasonably confident there aren't any leaks with the current cvs head 
source revision.

Regards.
Ross

On 2/12/2011 1:11 PM, Jason Jones wrote:
> Hello!
>
> I am having memory leaks when using Pthreads-Win32. I have attached a
> very simple example program that illustrates the problem. It is very
> simple:
>
> 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?
>
> Thanks,
>
> Jason

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-12-02 14:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-02  2:11 Possible memory leak in Pthreads-Win32 Jason Jones
2011-12-02 14:10 ` Ross Johnson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).