[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Thread: memory leak when using not detached thread?
From: |
Gernot Hillier |
Subject: |
Thread: memory leak when using not detached thread? |
Date: |
Mon, 9 Dec 2002 11:12:40 +0100 |
User-agent: |
KMail/1.4.3 |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi!
I'm no pthread guru, so perhaps I've misunderstood something. Please excuse
this ;-)
I narrowed my problem down to a very small test application. See attached
test.cpp file.
This program produces a memory leak - i.e. a finishing thread doesn't free its
resources.
I had a small look on the sources and the problem seems to be in
Thread::terminate():
if(pthread_self() != priv->_tid)
{
printf("grbml\n");
// in suspend thread cannot be cancelled or signaled
// ??? rigth
// ccxx_resume(priv->_tid);
// assure thread has ran before we try to cancel...
if(_start)
_start->post();
pthread_cancel(priv->_tid);
pthread_join(priv->_tid,NULL);
}
This doesn't get called as pthread_self() seems to be the same thread which
deletes this. So pthread_join isn't called and the resources aren't freed.
Now I thought Thread::final() won't run in the same thread context as my new
thread? So why doesn't this work?
Do I have to use Thread::detach() instead of Thread::start() when I want to
"delete this"?
Could you elaborate on the cited glibc bug mentioned in the Thread::detach()
docu? I asked a glibc developer and he told me that it's my fault if I don't
run pthread_join - no glibc bug.
I've seeked the archives a little bit but found no mail responding my
question. Sorry if this is a FAQ.
- --
Ciao,
Gernot
"Der Horizont vieler Menschen ist ein Kreis mit Radius Null - und das nennen
sie ihren Standpunkt." (A. Einstein)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)
iD8DBQE99Gyak997/GGeSeIRAl21AJ9ZsCP5I7ucAtdTkrmRHWH2FRUaigCgjsYA
g7ujTDi4IQHkJpU3WTgm06c=
=NjMu
-----END PGP SIGNATURE-----
test.cpp
Description: Text Data
- Thread: memory leak when using not detached thread?,
Gernot Hillier <=