By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,165 Members | 1,916 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,165 IT Pros & Developers. It's quick & easy.

stopping a boost::thread

P: n/a
Hi everyone,

I am trying to use the boost multithreading library. I am having a
problem as the join() function for the thread never returns. I am using
a boolean variable to indicate when the thread should stop running.
Here is basically a stub of what I am doing:
Code:

//........................................
bool m_RunThread = false;
scoped_ptr<boost::thread> myThread;
//.......................................

void MyObject::StartThread()
{
m_RunThread = true;
myThread.reset(new boost::thread(boost::bind
(&MyObject::MyThreadFunc, this)));

}

void MyObject::StopThread()
{
m_RunThread = false;
myThread.join(); // this function never returns!

... Never gets here....
}

void MyObject::MyThreadFunc()
{
while (m_RunThread)
{
// do something
}
}
However, the join() function in StopThread never returns. I think that
using a variable to synchronize this is probably not a good idea. Any
thoughts and suggestions?

Cheers,
xargy

Feb 6 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
de**********@gmail.com wrote:
Hi everyone,

I am trying to use the boost multithreading library. I am having a
problem as the join() function for the thread never returns. I am using
a boolean variable to indicate when the thread should stop running.
Here is basically a stub of what I am doing:
Code:

//........................................
bool m_RunThread = false;
scoped_ptr<boost::thread> myThread;
//.......................................

void MyObject::StartThread()
{
m_RunThread = true;
myThread.reset(new boost::thread(boost::bind
(&MyObject::MyThreadFunc, this)));

}

void MyObject::StopThread()
{
m_RunThread = false;
myThread.join(); // this function never returns!

... Never gets here....
}

void MyObject::MyThreadFunc()
{
while (m_RunThread)
{
// do something
}
}
However, the join() function in StopThread never returns. I think that
using a variable to synchronize this is probably not a good idea. Any
thoughts and suggestions?

Cheers,
xargy


You might try the Boost Users list:

http://boost.org/more/mailing_lists.htm#users

Cheers! --M

Feb 6 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.