From: "sam copydata" <sam@copydata.fr>
To: pthreads-win32@sourceware.org
Subject: Windows XP memory leak ??? [innocent newbie :)]
Date: Wed, 23 Apr 2008 14:51:00 -0000 [thread overview]
Message-ID: <29cb423f0804230751r358ad834l1fd0cfa3322b453d@mail.gmail.com> (raw)
Hi,
I'm working on a threaded project under Linux & Windows. This project
is almost developed under Linux and then ported to windows. When we
tried to check memory stability under windows we found some leaks
while there was none under Linux.
When program runs, it grows up in memory by 4 KB blocks only under
windows XP (home or pro version) but it do not moves under windows
server 2003 or under Linux.
After many tests i isolated this code which reproduce the leak of memory :
//////////////////////////////////////////////// main.cpp
#include <iostream>
#include <pthread.h>
using namespace std;
#ifdef WIN32
# define usleep Sleep
# include "crtdbg.h"
# include <Windows.h>
#endif
typedef struct toto_s toto_t;
struct toto_s
{
int ok;
};
void *testthread(void *a)
{
toto_t *test;
test = (toto_t *)a;
cout << "thread créé" << endl;
test->ok = 1;
return NULL;
}
int main()
{
pthread_t thread;
toto_t *data;
data = (toto_t *)malloc(sizeof(toto_t));
data->ok = 0;
for (int i = 100000; i; i--)
{
if (pthread_create(&thread, NULL, testthread, (void *)data))
{
cout << "erreur : impossible de créer le thread" << endl;
return -1;
}
pthread_detach(thread);
// testthread(data);
cout << "thread " << 100000 - i << " créé" << endl;
while (!data->ok)
usleep(100);
usleep(100);
data->ok = 0;
}
free(data);
return 0;
}
//////////////////////////////////////////////// End of main.cpp
I compile this code with prebuild version of pthread 2.7.0 or 2.8.0
with the same results.
I tried to do it in many other ways always with the same memory leak.
If someone have an idea, it would be very welcome, I'm on this since 3 days. :(
--
Sam.
reply other threads:[~2008-04-23 14:51 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=29cb423f0804230751r358ad834l1fd0cfa3322b453d@mail.gmail.com \
--to=sam@copydata.fr \
--cc=pthreads-win32@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).