The boost::thread
will store copy of its arguments. But you can simulate a reference by passing a reference_wrapper
with the help of boost::ref
. Also note that you don't need to call boost::bind
:
boost::thread t(&MyClass::CheckTimeoutThread, this, boost::ref(isStarted));
But note that you now have a race condiiton on isStarted
. You need to either synchrise access to it with, say, mutexes, or use an atomic type, if available on your platform (if you have C++11, then you can use std::atomic<bool>
, as suggested by @PeteBecker.)
Edit Obviously all of the above assumes that isStated
lives at least as long as the thread
that uses it. In practice, this means the thread must be done by the time aMethod
returns. Alternatively, you can make isStarted
a data member. But you still have to make sure to join the thread before the MyClass
destructor destroys it.