I have a MFC application which use boost thread. I have created several threads like m_pReadThread / m_pProcessThread / m_pWriteThread m_pProcessThread = boost::shared_ptrboost::thread(new boost::thread(boost::bind(&CMFCDlg::ProcessThreadBoost, this))); in each thread, the thread function structure looks like: { init; while(run == true) { // set break point here ... } cleanup code; // set break point here } I set break point When I run my application, one of the thread only reach the first break point once. The second break point never reached. What might be the problem? Since the code is part of a big project. I can not put code here. -- View this message in context: http://boost.2283326.n4.nabble.com/Thread-function-only-called-one-time-why-... Sent from the Boost - Users mailing list archive at Nabble.com.
I have a MFC application which use boost thread. I have created several threads like m_pReadThread / m_pProcessThread / m_pWriteThread
m_pProcessThread = boost::shared_ptrboost::thread(new boost::thread(boost::bind(&CMFCDlg::ProcessThreadBoost, this)));
in each thread, the thread function structure looks like: { init; while(run == true) { // set break point here ... } cleanup code; // set break point here }
I set break point When I run my application, one of the thread only reach the first break point once. The second break point never reached. What might be the problem?
Maybe the loop never breaks? Maybe you lock a mutex within the loop, and this causes a deadlock? Maybe some code within the loop raises an exception? Just step your loop line by line or, if it's impossible, print-out some log lines to trace it, like this: while(run == true) { log("point 1"); doSomeThing.... log("point 2"); doSomeMore.... log("point3"); } log("point4"); cleanup code;
2012/8/21 young
I have a MFC application which use boost thread. I have created several threads like m_pReadThread / m_pProcessThread / m_pWriteThread
m_pProcessThread = boost::shared_ptrboost::thread(new boost::thread(boost::bind(&CMFCDlg::ProcessThreadBoost, this)));
in each thread, the thread function structure looks like: { init; while(run == true) { // set break point here ... } cleanup code; // set break point here }
I set break point When I run my application, one of the thread only reach the first break point once. The second break point never reached. What might be the problem?
Since the code is part of a big project. I can not put code here.
Maybe your program ends before your threads end? For example I think this will terminate your threads before they finish: int main() { thread* a = new thread(...); thread* b = new thread(...); } And what you need is something like: int main() { thread* a = new thread(...); thread* b = new thread(...); a->join(); b->join(); } Regards, Kris
participants (3)
-
Igor R
-
Krzysztof Czainski
-
young