[osg-users] OpenThreads threading bug on creation/deletion (leads to crashes)

Adam Coates acoates at stanford.edu
Thu Sep 20 13:17:04 PDT 2007


I've attached the version I'm using that demonstrates the unusability
of the isRunning() flag.

The code pasted into the last e-mail is all that's necessary to
illustrate the crash, though it doesn't try to avoid it using the
'isRunning' flag.  You shouldn't need to modify the OpenThreads
library.

I get the following error after running the attached code:
"pure virtual method called
terminate called without an active exception
Aborted"

presumably because thread->run() is being called on an object that has
been trashed.

AC

On 9/20/07, Robert Osfield <robert.osfield at gmail.com> wrote:
> Hi Adam,
>
> Could you send the exact code that you can recreate the issue with.
>
> Robert.
>
> On 9/20/07, Adam Coates <acoates at stanford.edu> wrote:
> > Ah - just double-checked.  It'll crash just fine without adding the
> > usleep() to OpenThreads;  I had my builds mixed up.
> >
> > AC
> >
> > On 9/20/07, Adam Coates <acoates at stanford.edu> wrote:
> > > Hi, Robert,
> > >
> > > The following is sufficient (basically what you said):
> > >
> > > #include <OpenThreads/Thread>
> > >
> > > class MyThread : public OpenThreads::Thread {
> > > public:
> > >   void run(void) { }
> > > };
> > >
> > > int main(int argc, char* argv[]) {
> > >   {
> > >     MyThread thread;
> > >     thread.startThread();
> > >   }
> > >   while(1) ;
> > >   return 0;
> > > }
> > >
> > > You need the while(1) ; to prevent the process from dying and cleaning
> > > up the thread before it wrecks.  This alone wouldn't reproduce the bug
> > > because the interleaving doesn't happen (it's a very short window in
> > > which it can happen).  To force the bug, I added  ::usleep(1000000) at
> > > the beginning of ThreadPrivateActions::StartThread().
> > >
> > > AC
> > >
> > > On 9/20/07, Robert Osfield <robert.osfield at gmail.com> wrote:
> > > > Hi Adam,
> > > >
> > > > On 9/20/07, Adam Coates <acoates at stanford.edu> wrote:
> > > > > So, I just realized that the OSG folks are not synonymous with the
> > > > > OpenThreads folks.  ^_^  Sorry for dropping this on the wrong list
> > > > > then.
> > > >
> > > > Well OpenThreads list is a flat line, almost  all (99.9%) OpenThreads
> > > > activity and development is done by members of the OpenSceneGraph
> > > > community.  So this is probably the best place to raise issues like
> > > > this.  Responsibility for maintaining OpenThreads has also fallen on
> > > > my shoulders as it effectively became an orphaned project when the
> > > > original project lead got sucked into non coding management.
> > > >
> > > > >In that light, it may not even be considered a bug in OT,
> > > > > since, theoretically, it might be unfair to call the Thread destructor
> > > > > while the thread is running (even though I'm pretty sure they intended
> > > > > isRunning() to work as we'd expect).
> > > >
> > > > Well this type of usage is kinda abusing the Thread class, but I'd
> > > > still say this way a bug.
> > > >
> > > > > It should be possible to add a workaround in the following way:
> > > > >
> > > > > 1.  Before starting the thread, set a flag to indicate that the thread
> > > > > is "starting up".
> > > > > 2.  Have the thread's run() routine unset this flag.
> > > > >
> > > > > Before deleting the Thread, make sure that both the "starting up" flag
> > > > > and the isRunning flag are false.  One of these will have to be true
> > > > > if the thread has not reached the run() method yet, or has not
> > > > > completely exited from run() -- thus avoiding the problem.
> > > >
> > > > I'll have ponder in this issue, I'm more inclined to use a mutex in
> > > > some way that just a straight flag.
> > > >
> > > > > My question:  does somebody want me to implement this workaround and
> > > > > submit it to you?  Alternatively, I can just point out the break to
> > > > > the OpenThreads people and we can wait for a patch...
> > > >
> > > > It's best to just roll your sleeves up and get stuck in.  First up we
> > > > need a test that can reliably reproduce the error.  Would the
> > > > following code block do the trick?
> > > >
> > > >   {
> > > >        OpenThreads::Thread thread;
> > > >        thread.startThread();
> > > >    }
> > > >
> > > > Robert.
> > > > _______________________________________________
> > > > osg-users mailing list
> > > > osg-users at lists.openscenegraph.org
> > > > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> > > >
> > >
> > _______________________________________________
> > osg-users mailing list
> > osg-users at lists.openscenegraph.org
> > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> >
> _______________________________________________
> 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: ottest.cpp
Type: application/octet-stream
Size: 261 bytes
Desc: not available
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20070920/fb3331bf/attachment-0003.obj>


More information about the osg-users mailing list