Boost logo

Boost Users :

From: Igor R. (igor_rubinov_at_[hidden])
Date: 2008-05-20 10:04:30


Hi,
 
In both functions you bind a method of a local object. The local object might die before the thread has a chance to execute that method!
So either you must wait until the thread ends:
void test_boost_thread_1(){ M p(88); boost::thread pthd(boost::bind(&M::m_show, &p));
    pthd.join();}
or you must bind your object by value - then the copy of the original object will be executed.

Date: Tue, 20 May 2008 21:05:17 +0800From: hexiay_at_gmail.comTo: boost-users_at_lists.boost.orgSubject: [Boost-users] Could two boost threads with the same name run at the same time?Hi, all$B!$(BMy code looks like this:=============================================================// M is a class, m_show() is one of its methods.void test_boost_thread_1(){ M p(88); boost::thread pthd(boost::bind(&M::m_show, &p));}void test_boost_thread_2(){ M p(99); boost::thread pthd(boost::bind(&M::m_show, &p));}==============================================================="test_boost_thread_1()" and "test_boost_thread_2()" are running at the same time ,but I find that the output is wrong.If I changed the thread name "pthd" in "test_boost_thread_()" to other name , not "pthd" , it looks ok. why ? ........Now , many other threads want to run " test_boost_thread_1() " at the "same" time, How could I make it ok ?Thanks for your time.Best Regards.
_________________________________________________________________
Discover the new Windows Vista
http://search.msn.com/results.aspx?q=windows+vista&mkt=en-US&form=QBRE



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net