That all makes sense and seemed to fix the problem.  Thanks for the fast reply.

 

-Rob Yull

 

From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Craig Henderson
Sent: Wednesday, July 29, 2009 10:47 AM
To: boost-users@lists.boost.org
Subject: Re: [Boost-users] Race condition with Boost::Thread

 

 

2009/7/29 Craig Henderson <cdm.henderson@googlemail.com>

 

class WorkerThread

{

public:

      typedef     boost::function<void ()>      JobType;

 

      WorkerThread()

      {

            m_Thread = boost::thread(boost::bind(&WorkerThread::run, boost::ref(this)));

       }

 

      ~WorkerThread()

      {

            while (!m_Running)

                ;

            m_Thread.join();

            m_Running = false;

      }

 

      const bool isRunning() const

      {

            return m_Running;

      }

 

private:

      volatile    bool  m_Running;

      boost::thread     m_Thread;

 

      void run()

      {

            m_Running = true;

            BOOST_ASSERT(isRunning());

      }

 

private:

      WorkerThread(const WorkerThread& rhs);

      WorkerThread& operator = (const WorkerThread& rhs);

};

 

Regards

-- Craig

 

You need to initial m_Running=false; in the ctor, too. 

-- Craig