473,413 Members | 1,875 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

stopping a boost::thread

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
1 7707
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: dingounan | last post by:
how to compile boost.thread,and set it? I have trouble. platform: windows XP compiler: Borland C++ Compiler 5.5.1 commandline tools thanks.
4
by: Lighter | last post by:
#include <boost/thread/thread.hpp> #include <iostream> using namespace std; using namespace boost; void hello() { cout << "Hello world, I'm a thread!" << endl; }
5
by: linyanhung | last post by:
I used a boost multi thread in VS 2005 on a Duo Core PC, and made a two thread process. The code is something like this: #include <boost/thread/thread.hpp> void fun1() { //do something
3
by: Gary Wessle | last post by:
#include <boost/thread/thread.hpp> #include <iostream> using namespace std; class waiter { public: waiter(); void waiting(); void preform();
4
by: Gary Wessle | last post by:
Hi given the Boost thread example here http://www-eleves-isia.cma.fr/documentation/BoostDoc/boost_1_29_0/libs/thread/example/thread.cpp the code below attempts to run the example thread while...
2
by: Chameleon | last post by:
Why this strange output? Why so many d'tor calls? The code: ---------------------------------------------------------- #include <cstdio> #include <boost/thread/thread.hpp> class A {
2
by: Hans Mull | last post by:
Hi! I'm experimenting with boost::thread. I have a GUI application with a slot function: void someFunction(){...} void Frame::OnOkButtonClick(...) { switch(someInteger) { case 0: break
3
by: Lars Uffmann | last post by:
I have this wxWidgets OnButtonClick event handler, that apparently holds a lock on all widgets in my form, but this event handler is supposed to end a thread in the background - while that thread...
1
by: Boogie | last post by:
Hi, A specific problem arises when I try to use boost::thread 1.35.0 with Borland Turbo 2006. Code below compiles but when run it throws (in commented line - thread creation): "assertion...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.