public inbox for pthreads-win32@sourceware.org
 help / color / mirror / Atom feed
* Memory leak with detached threads
@ 2006-10-29 18:42 Giuliano Catrambone
  2006-10-29 20:20 ` Tim Theisen
  0 siblings, 1 reply; 6+ messages in thread
From: Giuliano Catrambone @ 2006-10-29 18:42 UTC (permalink / raw)
  To: pthreads-win32

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

Hi all,
    I found a memory leak working with detached threads.
    I just made a simple C code to demonstrate where I have the memory leak.

    Running the attached C code I saw about 4KB of memory leak every 20 
iteration.

    I'm using pthreads-dll-2005-03-08.

    Could you tell me if I'm wronging something or if it is a bug?
    Thanks in advance
       giu

-- 
-----------------------------------------------------------------
Giuliano Catrambone
Director, Professional Services

Open source projects:
http://sourceforge.net/projects/catralibraries/
http://sourceforge.net/projects/openstreaming/

CatraSoftware:
Home page: http://www.catrasoftware.it

Streaming page:
http://www.catrasoftware.it/Streaming/CatraStreamingPlatform.htm

Mobile +39.393.8816655
Fixed: +39.02.90377228
Skype: Catrambone Giuliano
msn: giulianocatrambone@hotmail.com
Jabber: giuliano.catrambone@Jabber.org
Yahoo: giuliano.catrambone
-----------------------------------------------------------------



[-- Attachment #2: memoryLeak.cpp --]
[-- Type: text/x-c++src, Size: 855 bytes --]


#include <iostream>
#include <pthread.h>
#include <windows.h>

void *runFunction (void *pvPThread)

{

	std:: cout << "Inside the thread" << std:: endl;

	Sleep (300);


	return (void *) NULL;

}

int main ()

{
	pthread_t			_pThread;
	pthread_attr_t		_pThreadAttribute;


	for (long lIndex = 0; lIndex < 1000; lIndex++)
	{
		std:: cout << "Index: " << lIndex << std:: endl;

		std:: cout << pthread_attr_init (&_pThreadAttribute) << std:: endl;

		std:: cout << pthread_attr_setdetachstate (&_pThreadAttribute, PTHREAD_CREATE_DETACHED)
			<< std:: endl;

		std:: cout << pthread_create (&_pThread, &_pThreadAttribute, runFunction, NULL) << std:: endl;

		// std:: cout << pthread_join (_pThread, &pvStatus) << std:: endl;

		std:: cout << pthread_attr_destroy (&_pThreadAttribute) << std:: endl;

		Sleep (300);
	}

	Sleep (1000 * 1000);

	return 0;
}


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

* RE: Memory leak with detached threads
  2006-10-29 18:42 Memory leak with detached threads Giuliano Catrambone
@ 2006-10-29 20:20 ` Tim Theisen
  2006-10-30 22:03   ` Giuliano Catrambone
  0 siblings, 1 reply; 6+ messages in thread
From: Tim Theisen @ 2006-10-29 20:20 UTC (permalink / raw)
  To: Giuliano Catrambone, pthreads-win32

Did you consider using the latest version?

The current version is 2.7.0 (2005-06-04)

http://sourceware.org/pthreads-win32/

Version 2.6.0 specifically mentions a resource leak with
pthread_detach():

* pthread_detach() now reclaims remaining thread resources if called
after
the target thread has terminated. Previously, this routine did nothing
in
this case.

http://sourceware.org/pthreads-win32/news.html

 
...Tim
--
       Tim Theisen                     Lead Research Software Engineer
Phone: +1 608 824 2848                 TomoTherapy Incorporated
  Fax: +1 608 824 2996                 1240 Deming Way
  Web: http://www.tomotherapy.com      Madison, WI 53717-1954  


-----Original Message-----
From: pthreads-win32-owner@sourceware.org
[mailto:pthreads-win32-owner@sourceware.org] On Behalf Of Giuliano
Catrambone
Sent: Sunday, October 29, 2006 13:43
To: pthreads-win32@sources.redhat.com
Subject: Memory leak with detached threads

Hi all,
    I found a memory leak working with detached threads.
    I just made a simple C code to demonstrate where I have the memory
leak.

    Running the attached C code I saw about 4KB of memory leak every 20
iteration.

    I'm using pthreads-dll-2005-03-08.

    Could you tell me if I'm wronging something or if it is a bug?
    Thanks in advance
       giu

--
-----------------------------------------------------------------
Giuliano Catrambone
Director, Professional Services

Open source projects:
http://sourceforge.net/projects/catralibraries/
http://sourceforge.net/projects/openstreaming/

CatraSoftware:
Home page: http://www.catrasoftware.it

Streaming page:
http://www.catrasoftware.it/Streaming/CatraStreamingPlatform.htm

Mobile +39.393.8816655
Fixed: +39.02.90377228
Skype: Catrambone Giuliano
msn: giulianocatrambone@hotmail.com
Jabber: giuliano.catrambone@Jabber.org
Yahoo: giuliano.catrambone
-----------------------------------------------------------------


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

* Re: Memory leak with detached threads
  2006-10-29 20:20 ` Tim Theisen
@ 2006-10-30 22:03   ` Giuliano Catrambone
  0 siblings, 0 replies; 6+ messages in thread
From: Giuliano Catrambone @ 2006-10-30 22:03 UTC (permalink / raw)
  To: Tim Theisen, pthreads-win32

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

Hi Tim, all,
    I tested the C code using the prebuilt-dll-2-7-0-release but I 
continue to have the
    memory leak.

    Could you test the code I attached to verify that the memory leak is 
really present
    in order to made a fix for it?
    Thanks for your help in advance
       giu

Tim Theisen wrote:
> Did you consider using the latest version?
>
> The current version is 2.7.0 (2005-06-04)
>
> http://sourceware.org/pthreads-win32/
>
> Version 2.6.0 specifically mentions a resource leak with
> pthread_detach():
>
> * pthread_detach() now reclaims remaining thread resources if called
> after
> the target thread has terminated. Previously, this routine did nothing
> in
> this case.
>
> http://sourceware.org/pthreads-win32/news.html
>
>  
> ...Tim
> --
>        Tim Theisen                     Lead Research Software Engineer
> Phone: +1 608 824 2848                 TomoTherapy Incorporated
>   Fax: +1 608 824 2996                 1240 Deming Way
>   Web: http://www.tomotherapy.com      Madison, WI 53717-1954  
>
>
> -----Original Message-----
> From: pthreads-win32-owner@sourceware.org
> [mailto:pthreads-win32-owner@sourceware.org] On Behalf Of Giuliano
> Catrambone
> Sent: Sunday, October 29, 2006 13:43
> To: pthreads-win32@sources.redhat.com
> Subject: Memory leak with detached threads
>
> Hi all,
>     I found a memory leak working with detached threads.
>     I just made a simple C code to demonstrate where I have the memory
> leak.
>
>     Running the attached C code I saw about 4KB of memory leak every 20
> iteration.
>
>     I'm using pthreads-dll-2005-03-08.
>
>     Could you tell me if I'm wronging something or if it is a bug?
>     Thanks in advance
>        giu
>
> --
> -----------------------------------------------------------------
> Giuliano Catrambone
> Director, Professional Services
>
> Open source projects:
> http://sourceforge.net/projects/catralibraries/
> http://sourceforge.net/projects/openstreaming/
>
> CatraSoftware:
> Home page: http://www.catrasoftware.it
>
> Streaming page:
> http://www.catrasoftware.it/Streaming/CatraStreamingPlatform.htm
>
> Mobile +39.393.8816655
> Fixed: +39.02.90377228
> Skype: Catrambone Giuliano
> msn: giulianocatrambone@hotmail.com
> Jabber: giuliano.catrambone@Jabber.org
> Yahoo: giuliano.catrambone
> -----------------------------------------------------------------
>
>
>
>
>   


-- 
-----------------------------------------------------------------
Giuliano Catrambone
Director, Professional Services

Open source projects:
http://sourceforge.net/projects/catralibraries/
http://sourceforge.net/projects/openstreaming/

CatraSoftware:
Home page: http://www.catrasoftware.it

Streaming page:
http://www.catrasoftware.it/Streaming/CatraStreamingPlatform.htm

Mobile +39.393.8816655
Fixed: +39.02.90377228
Skype: Catrambone Giuliano
msn: giulianocatrambone@hotmail.com
Jabber: giuliano.catrambone@Jabber.org
Yahoo: giuliano.catrambone
-----------------------------------------------------------------



[-- Attachment #2: memoryLeak.cpp --]
[-- Type: text/x-c++src, Size: 855 bytes --]


#include <iostream>
#include <pthread.h>
#include <windows.h>

void *runFunction (void *pvPThread)

{

	std:: cout << "Inside the thread" << std:: endl;

	Sleep (300);


	return (void *) NULL;

}

int main ()

{
	pthread_t			_pThread;
	pthread_attr_t		_pThreadAttribute;


	for (long lIndex = 0; lIndex < 1000; lIndex++)
	{
		std:: cout << "Index: " << lIndex << std:: endl;

		std:: cout << pthread_attr_init (&_pThreadAttribute) << std:: endl;

		std:: cout << pthread_attr_setdetachstate (&_pThreadAttribute, PTHREAD_CREATE_DETACHED)
			<< std:: endl;

		std:: cout << pthread_create (&_pThread, &_pThreadAttribute, runFunction, NULL) << std:: endl;

		// std:: cout << pthread_join (_pThread, &pvStatus) << std:: endl;

		std:: cout << pthread_attr_destroy (&_pThreadAttribute) << std:: endl;

		Sleep (300);
	}

	Sleep (1000 * 1000);

	return 0;
}


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

* Re: Memory leak with detached threads
  2006-10-29 19:02 Stephen Croall
@ 2006-10-29 20:10 ` Giuliano Catrambone
  0 siblings, 0 replies; 6+ messages in thread
From: Giuliano Catrambone @ 2006-10-29 20:10 UTC (permalink / raw)
  To: Stephen Croall; +Cc: pthreads-win32

Hi Stephen,
    the initial version of the code was using pthread_detach() and I had 
the same issue,
    a leak about 4KB every 20 iterations.
    Do you have some other ideas?
    Thanks
       giu

Stephen Croall wrote:
> DOH!
>
> Just realised that you are calling pthread_attr_setdetachstate().  You
> could change to calling pthread_detach() to see if the memory leak still
> happens.  We use this call a lot in our code and have no problems with
> leaks.
>
> Steve.
>
>
>   


-- 
-----------------------------------------------------------------
Giuliano Catrambone
Director, Professional Services

Open source projects:
http://sourceforge.net/projects/catralibraries/
http://sourceforge.net/projects/openstreaming/

CatraSoftware:
Home page: http://www.catrasoftware.it

Streaming page:
http://www.catrasoftware.it/Streaming/CatraStreamingPlatform.htm

Mobile +39.393.8816655
Fixed: +39.02.90377228
Skype: Catrambone Giuliano
msn: giulianocatrambone@hotmail.com
Jabber: giuliano.catrambone@Jabber.org
Yahoo: giuliano.catrambone
-----------------------------------------------------------------


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

* RE: Memory leak with detached threads
@ 2006-10-29 19:02 Stephen Croall
  2006-10-29 20:10 ` Giuliano Catrambone
  0 siblings, 1 reply; 6+ messages in thread
From: Stephen Croall @ 2006-10-29 19:02 UTC (permalink / raw)
  To: Giuliano Catrambone; +Cc: pthreads-win32

DOH!

Just realised that you are calling pthread_attr_setdetachstate().  You
could change to calling pthread_detach() to see if the memory leak still
happens.  We use this call a lot in our code and have no problems with
leaks.

Steve.

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

* RE: Memory leak with detached threads
@ 2006-10-29 18:54 Stephen Croall
  0 siblings, 0 replies; 6+ messages in thread
From: Stephen Croall @ 2006-10-29 18:54 UTC (permalink / raw)
  To: Giuliano Catrambone; +Cc: pthreads-win32

Hi,

You aren't freeing the handle to the created thread :)

If you aren't interested in using the handle later on call
pthread_detach() to free the resources for the thread handle.  


Steve.

-- 

J. Architect/Principal Engineer, Tibco Software Ltd.
T. +44 (0) 1792 360773
M. +44 (0) 7788 971394
E. scroall@tibco.com
W. www.tibco.com
 

> -----Original Message-----
> From: pthreads-win32-owner@sourceware.org 
> [mailto:pthreads-win32-owner@sourceware.org] On Behalf Of 
> Giuliano Catrambone
> Sent: 29 October 2006 19:43
> To: pthreads-win32@sources.redhat.com
> Subject: Memory leak with detached threads
> 
> Hi all,
>     I found a memory leak working with detached threads.
>     I just made a simple C code to demonstrate where I have 
> the memory leak.
> 
>     Running the attached C code I saw about 4KB of memory 
> leak every 20 
> iteration.
> 
>     I'm using pthreads-dll-2005-03-08.
> 
>     Could you tell me if I'm wronging something or if it is a bug?
>     Thanks in advance
>        giu
> 
> -- 
> -----------------------------------------------------------------
> Giuliano Catrambone
> Director, Professional Services
> 
> Open source projects:
> http://sourceforge.net/projects/catralibraries/
> http://sourceforge.net/projects/openstreaming/
> 
> CatraSoftware:
> Home page: http://www.catrasoftware.it
> 
> Streaming page:
> http://www.catrasoftware.it/Streaming/CatraStreamingPlatform.htm
> 
> Mobile +39.393.8816655
> Fixed: +39.02.90377228
> Skype: Catrambone Giuliano
> msn: giulianocatrambone@hotmail.com
> Jabber: giuliano.catrambone@Jabber.org
> Yahoo: giuliano.catrambone
> -----------------------------------------------------------------
> 
> 
> 

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

end of thread, other threads:[~2006-10-30 22:03 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-10-29 18:42 Memory leak with detached threads Giuliano Catrambone
2006-10-29 20:20 ` Tim Theisen
2006-10-30 22:03   ` Giuliano Catrambone
2006-10-29 18:54 Stephen Croall
2006-10-29 19:02 Stephen Croall
2006-10-29 20:10 ` Giuliano Catrambone

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).