Boost logo

Boost Users :

From: Ovanes Markarian (om_boost_at_[hidden])
Date: 2006-08-23 04:54:30


Hi!

To create a new message please do not reply to existing messages and change the subject. Each
message has an Id (Thread-Index) in the header which causes the mailing list to sort it as reply
to the old message.

With Kind Regards,

Ovanes Markarian

On Wed, August 23, 2006 09:25, Aubrey, Jason wrote:
> Hi,
>
> My Environment:
> * MSVC 8.0
> * boost v1.33.1
>
> Using the example program below, I'm getting an assertion within boost's
> thread class during a call to join. join() is being called twice: 1)
> in main() 2) in ~Thread(). If I remove one of the calls to join() the
> assertion goes away. Though this example's usage seems redundant such
> behavior should be similar to the scenario of multiple threads waiting
> on the same thread via join().
>
> Help would be appreciated.
>
> Regards,
> Jason
>
> // --------------------------------- BEGIN EXAMPLE PROGRAM
> ---------------------------
> // Assertion failed: m_joinable, file
> C:\...\boost\boost_1_33_1\libs\thread\build\..\src\thread.cpp, line 223
> // Call Stack begins in the following code at the end of main() within
> ~Thread() in the call to join().
>
> #include <boost/bind.hpp>
> #include <boost/noncopyable.hpp>
> #include <boost/shared_ptr.hpp>
> #include <boost/thread/thread.hpp>
> #include <boost/thread/xtime.hpp>
>
> // This class misuses inheritance, but is provided for those
> // familiar with Java syntax that don't care
> class Thread : public boost::noncopyable
> {
> private:
> boost::shared_ptr<boost::thread> _thread;
>
> public:
> Thread(){}
> virtual ~Thread() { join(); }
>
> void join()
> {
> if ( _thread )
> _thread->join();
> }
>
> virtual void run() = 0;
>
> void start()
> {
> if ( !_thread )
> _thread.reset( // Reference to the thread
> new boost::thread( // New thread of execution
> boost::bind(&Thread::run, this) // Functor calls
> run()
> ));
> }
> };
>
> struct MyThread : public Thread
> {
> void run() {}
> };
>
> void main()
> {
> MyThread t;
> t.start();
> t.join(); // No assertion if this line is commented
> return;
> }
>
> // --------------------------------- END EXAMPLE PROGRAM
> ---------------------------
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>


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