Thanks for the reply Paul.  I was calling join because i wanted the main calling
thread to block until myThread was finished.  I know it doesn't make much sense
to do it that way in this contrived example but in my actual application it
would be nice to do this between scenario teardown and setup/restart.

Per your suggestion I modified my main to this:
void main()
{
   OpenThreadObject* myThread = new OpenThreadObject;
   myThread->start();
   myThread->cancel();
  
   // I assume the "!" in your example was an error?
   while (myThread ->isRunning())
   {
      OpenThreads::Thread::microSleep(100);
   }

   myThread->start();

   while (myThread->isRunning())
   {
      OpenThreads::Thread::microSleep(100);
   }
}

Unfortunately it dies the same as before.  One around this that I've found is
not use "cancel()" at all but to create my own cancel mechanise like this (from
my actual app):

void DatabaseThread::TerminateThread()
{   
   if (OpenThreads::Thread::CurrentThread() != this)
   {
      // Block until the thread is canceled
      if (isRunning())
      { 
         // mShouldTerminate is an atomic var that is checked
         // periodically inside run() to know when to bail out

         ++mShouldTerminate;
         join();
         --mShouldTerminate;

         // Cleaning up personal data
         mPublicActorList.clear();
         mPrivateActorList.clear();
      }  
   }
   else
   {
      LOG_ERROR("Trying to terminate self.");
   }
}

I would prefer to do this the "right" way whatever that may be.

Thanks,
Michael

_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to