[osg-users] OpenThread leak ?

Adam Coates acoates at stanford.edu
Tue Sep 25 20:31:50 PDT 2007


Because I am a sick human being, I coded a fix for this problem in
case anyone else should care.  A diff is attached.  Basically, I just
added some checking to detach() and join() so that if the thread has
not yet been joined or detached successfully by its owner when it is
destroyed, it will detach in the destructor.

Also, it was possible for detach() or join() to crash if called before
start() because pd->tid is uninitialized at that point.  I included an
error check for this and tried to return error codes consistent with
the behavior on Linux (which should be fairly standard for POSIX).

AC

On 9/25/07, Adam Coates <acoates at stanford.edu> wrote:
> Makes sense to me -- but at the least this is now a "documented" issue
> in case others are curious and need to solve it for their own reasons.
>
> Cheers,
> AC
>
> On 9/25/07, Robert Osfield <robert.osfield at gmail.com> wrote:
> > On 9/25/07, Adam Coates <acoates at stanford.edu> wrote:
> > > I looked into this a tad more;  it looks like it is indeed caused by
> > > the thread not being detached.  I added the line:
> > >
> > >     pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED);
> > >
> > > before the thread creation so that the thread will clean up
> > > automatically.  This eliminates the memory leak.  This is a bad hack,
> > > since it will break the join() and detach() functions.  However,
> > > before I tried this, I tried calling join() and detach() on the Thread
> > > object, but that only leads to a segfault (not sure why yet).
> >
> > Just a quick comment, in early days of OpenThreads/OSG development we
> > tried out join() but found problems with it and certain platforms.  I
> > can't recall which platforms, nor which combinations of usage, nor the
> > actual symptoms exhibited - its was around 6 years ago.
> >
> > As for a small memory leak on exit from an app, well unix will clean
> > this up for you anyway on exit from the app, so while it'd be good
> > practice to solve it, its not going to make any significance to any
> > application built on the OSG.  Given how many other tasks I have on my
> > plate I'll leave this lower priority issue to others to chase up if
> > they fancy :-)
> >
> > Robert.
> >
> > Robert.
> > _______________________________________________
> > osg-users mailing list
> > osg-users at lists.openscenegraph.org
> > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> >
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenThreads.diff
Type: application/octet-stream
Size: 1907 bytes
Desc: not available
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20070925/4a9e4d30/attachment-0003.obj>


More information about the osg-users mailing list