
27 Aug
2004
27 Aug
'04
2:56 p.m.
Doug Gregor wrote:
On Aug 27, 2004, at 4:37 AM, Howard Cole wrote:
myclass test_instance; boost::thread test_thread(test_instance); test_thread.join();
Just change the thread construction to use boost::ref:
boost::thread test_thread(boost::ref(test_instance));
Yep. In addition you might want to consider using shared_ptr, because your ref-enhanced code will now need to keep track of test_instance and ensure that it isn't destroyed before the thread has finished. shared_ptr<myclass> px( new myclass ); thread test_thread( &myclass::do_thread_stuff, px ); You can also use pimpl to hide the shared_ptr in myclass, but the above is easier, and you can make myclass noncopyable.