Boost logo

Boost Users :

Subject: Re: [Boost-users] Race condition with Boost::Thread
From: Rob Yull (ryull_at_[hidden])
Date: 2009-07-29 11:00:57


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

 

-Rob Yull

 

From: boost-users-bounces_at_[hidden]
[mailto:boost-users-bounces_at_[hidden]] On Behalf Of Craig Henderson
Sent: Wednesday, July 29, 2009 10:47 AM
To: boost-users_at_[hidden]
Subject: Re: [Boost-users] Race condition with Boost::Thread

 

 

2009/7/29 Craig Henderson <cdm.henderson_at_[hidden]>

 

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

 



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net