[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Thread: memory leak when using not detached thread?
From: |
David Sugar |
Subject: |
Re: Thread: memory leak when using not detached thread? |
Date: |
Tue, 10 Dec 2002 09:19:35 -0500 (EST) |
A thread cannot delete it's own context or join itself. To make a thread
that is a self running object that self-deletes, one has to detach the
thread. However, there is very definately a known bug in at least some
glibc releases that when a detached thread exits, it will not clean up
it's stack frame allocations because that code only existed in the
pthread_join implimentation, and, of course, one cannot self join...
On Mon, 9 Dec 2002, Gernot Hillier wrote:
> --[PinePGP]--------------------------------------------------[begin]--
> 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)
> --[PinePGP]-----------------------------------------------------------
> gpg: Warning: using insecure memory!
> gpg: Signature made Mon 09 Dec 2002 05:12:42 AM EST using DSA key ID 619E49E2
> gpg: Can't check signature: public key not found
> PinePGP: Encryption backend encountered error.
> --[PinePGP]----------------------------------------------------[end]--
>