How can I start a thread inside an object? For example,
class ABC
{
public:
void Start();
double x;
boost::thread m_thread;
};
ABC abc;
... do something here ...
... how can I start the thread with Start() function?, ...
... e.g., abc.m_thread = boost::thread(&abc.Start()); ...
So that later I can do something like,
abc.thread.interrupt();
abc.thread.join();
Thanks.
You need neither bind, nor pointer.
boost::thread m_thread;
//...
m_thread = boost::thread(&ABC::Start, abc);
Use boost.bind:
boost::thread(boost::bind(&ABC::Start, abc));
You probably want a pointer (or a shared_ptr):
boost::thread* m_thread;
m_thread = new boost::thread(boost::bind(&ABC::Start, abc));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With