* Thread causing memory leaks...
@ 2005-08-19 13:37 Mehmet Tek
0 siblings, 0 replies; 2+ messages in thread
From: Mehmet Tek @ 2005-08-19 13:37 UTC (permalink / raw)
To: linux-c-programming
Hi all,
After debugging for a number of hours, I found out that the very basics of my
thread usage is causing memory leaks. (I checked it with mtrace and valgrind,
they both say that there is memory leak.)
I have a very simple program below that leaks memory. Can anyone tell me if I
am doing sth wrong, or is it actually some bug in the native thread
implementation?
Any feedback would be appreciated...
Thanks,
Mehmet
PS: I am using Linux 2.4.21 (SuSE 9.0) with gcc 3.3.1 on a AMD64 machine.
===========================================================================
#include <iostream>
#include <pthread.h>
#include <mcheck.h>
using namespace std;
void *thFunction(void *arg) {
cout << " Thread started" << endl;
cout << " Thread ending" << endl;
return NULL;
}
int main() {
pthread_t th;
// mtrace();
cout << " Spawning the thread" << endl;
pthread_create(&th, NULL, thFunction, NULL);
pthread_join(th, NULL);
// muntrace();
return 0;
}
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Thread causing memory leaks...
[not found] <200508191714586.SM02404@037f27dd816a40c>
@ 2005-08-22 8:36 ` Jean-Philippe Andriot
0 siblings, 0 replies; 2+ messages in thread
From: Jean-Philippe Andriot @ 2005-08-22 8:36 UTC (permalink / raw)
To: Mehmet Tek; +Cc: linux-c-programming
Hi
You should use "pthread_exit" instead of "return NULL"
JP
Mehmet Tek wrote:
>Hi all,
>
>After debugging for a number of hours, I found out that the very basics of my
>thread usage is causing memory leaks. (I checked it with mtrace and valgrind,
>they both say that there is memory leak.)
>
>I have a very simple program below that leaks memory. Can anyone tell me if I
>am doing sth wrong, or is it actually some bug in the native thread
>implementation?
>
>Any feedback would be appreciated...
>
>Thanks,
>Mehmet
>
>PS: I am using Linux 2.4.21 (SuSE 9.0) with gcc 3.3.1 on a AMD64 machine.
>
>===========================================================================
>
>#include <iostream>
>#include <pthread.h>
>#include <mcheck.h>
>
>using namespace std;
>
>void *thFunction(void *arg) {
>
> cout << " Thread started" << endl;
>
> cout << " Thread ending" << endl;
>
> return NULL;
>
>}
>
>int main() {
>
> pthread_t th;
>
> // mtrace();
>
> cout << " Spawning the thread" << endl;
>
> pthread_create(&th, NULL, thFunction, NULL);
>
> pthread_join(th, NULL);
>
> // muntrace();
>
> return 0;
>}
>
>
>-
>To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
>the body of a message to majordomo@vger.kernel.org
>More majordomo info at http://vger.kernel.org/majordomo-info.html
>
>
>
>
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2005-08-22 8:36 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-08-19 13:37 Thread causing memory leaks Mehmet Tek
[not found] <200508191714586.SM02404@037f27dd816a40c>
2005-08-22 8:36 ` Jean-Philippe Andriot
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 NNTP newsgroup(s).