Boost logo

Boost :

From: Heckl, Jochen (ext) (jochen.heckl.ext_at_[hidden])
Date: 2008-04-30 10:21:32

I think boost::barrier is what you look for.

Supposed an algorithm function looks like this

void MyAlgorithm( boost::barrier& i_FistAlgorithmDone )
        // run algo


Then the main thread would look like this:

// 2 waits, one from the main thread, the other from the first algo
boost::barrier FistAlgorithmDone( 2 );

boost::thread_group tg;
// ...

// pass in FistAlgorithmDone to your algorithm functions
Tg.create_thread( std::tr1::bind( &MyAlgorithm, std::tr1::ref(
FistAlgorithmDone ) );
// crate next thread

// wait for the first algo to finish

// wait for the remaining algos to finish
boost::thread* first = tg.join_one();

I can't verify if this compiles atm. Sry for that.
I hope this is what you look for.

Best Jochen

-----Original Message-----
From: boost-bounces_at_[hidden]
[mailto:boost-bounces_at_[hidden]] On Behalf Of vicente.botet
Sent: Wednesday, April 30, 2008 1:29 PM
To: boost_at_[hidden]
Subject: [boost] [thread]joining the first thread finishing from a group


I have several implementations of the same function with different
algorithms. I want to launch these in parallel and join the one
finishing the first, and stop the others.

I have started and in my solution I need to wrap the function in order
to make the needed synchronization, which seam not quite satisfactory.

Is there an easy way to join the first thread that finish from a thread
group and getting it?

    boost::thread_group tg;
    // ...
    boost::thread* first = tg.join_one();

Do you find useful this feature?

Vicente Juan Botet Escriba
Unsubscribe & other changes:

Boost list run by bdawes at, gregod at, cpdaniel at, john at