public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* ~100KB usleep() memory leak
@ 2012-03-19 17:15 Konstantin Ivlev
  2012-03-19 17:37 ` Corinna Vinschen
  0 siblings, 1 reply; 4+ messages in thread
From: Konstantin Ivlev @ 2012-03-19 17:15 UTC (permalink / raw)
  To: cygwin

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

Hi All,

I have noticed ~100KB usleep() memory leak then compile mine
application under Cygwin. On Mac OS X 10.7 Lion it works fine (no
leak).
I am using Cygwin 1.7.11 version.
so, each call of usleep() I can see in Task Manager or Process
Explorer about ~100KB of memory are leaked. it is not so problematic,
but if I am using thread pool (e.g. 16 threads) it will leak about
~1MB per seconds, and several minutes of running application are
enough to waste all available memory ~4GB.

it is easy to reproduce. compile the following really simple source code :

#include <unistd.h>

int main()
{
	for (;;)
	{
		usleep(10);
	}
}

>g++ main.cpp

then run :

>./a.exe

and observe memory is leaking. to notice more huge memory leak,
compile the following simple example simulating thread pool :

#include <unistd.h>
#include <pthread.h>

void * ThreadProc(void *)
{
    for (;;)
	{
		usleep(10);
	}
	return NULL;
}

int main()
{
	size_t count = 16; // specify more to see bigger leak!
	pthread_t id;
	for (size_t i(0); i < count; ++i)
	pthread_create(&id, NULL, ThreadProc, NULL);
	for (;;);
	return NULL;
}

> g++ main.cpp

and run :

> ./a.exe

and observe huge and fast leaking memory. and if you comment usleep
call, memory leak will disapper.

I would be grateful if you could possibly advice something on this issue.

P.S. "cygcheck -s -v -r > cygcheck.out" execution log is in attachment
I am pleasant to enclose.

[-- Attachment #2: cygcheck.out --]
[-- Type: application/octet-stream, Size: 303803 bytes --]

[-- Attachment #3: sample1.cpp --]
[-- Type: text/x-c++src, Size: 73 bytes --]

#include <unistd.h>

int main()
{
	for (;;)
	{
		usleep(10);
	}
}

[-- Attachment #4: sample2.cpp --]
[-- Type: text/x-c++src, Size: 256 bytes --]

#include <unistd.h>
#include <pthread.h>

void * ThreadProc(void *)
{
    for (;;)
	{
		usleep(10);
	}
	return NULL;
}

int main()
{
	pthread_t id;
	for (size_t i(0); i < 16; ++i)
	pthread_create(&id, NULL, ThreadProc, NULL);
	for (;;);
}

[-- Attachment #5: Type: text/plain, Size: 218 bytes --]

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

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

end of thread, other threads:[~2012-03-20  2:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-19 17:15 ~100KB usleep() memory leak Konstantin Ivlev
2012-03-19 17:37 ` Corinna Vinschen
2012-03-19 21:16   ` marco atzeri
2012-03-20  2:05     ` Konstantin Ivlev

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