Boost logo

Boost Users :

Subject: Re: [Boost-users] thread problem
From: Philipp Kraus (philipp.kraus_at_[hidden])
Date: 2010-11-27 12:24:59


On 2010-11-27 18:23:26 +0100, Steven Watanabe said:

> AMDG
>
> On 11/27/2010 9:01 AM, Kraus Philipp wrote:
>> I have some problems with a thread call. I have a call with a method
>> in that should create a thread:
>>
>> void myclass::mymethod( void )
>> {
>> boost::thread l_thread( boost::bind( &myclass::threadrun, this ) );
>> l_thread.join(); <= this blocks
>> }
>>
>> My threadrun method shows:
>>
>> void myclass:threadrun( void )
>> {
>> while (m_listenerrunnging) {
>> boost::this_thread::yield();
>> }
>> }
>>
>> The join starts the threadrun method but it blocks the main run. I
>> have got a class which should create only one thread (in itsself),
>> that should run until the class is destroyed. The threadrun method
>> reads some data at a network device in asychron calls, so the
>> threadrun can sleep during running.
>> How can I do this in a correct way?
>
> Creating the boost::thread object starts the thread.
> join blocks until the thread is finished. If you
> don't want the main thread to block, don't
> call join.

the constructors of boost::thread starts my function directly in background?


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