|
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
//...
i_FistAlgorithmDone.wait();
}
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
FistAlgorithmDone.wait();
// 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
ofthreads
Hello,
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?
Regards
_____________________
Vicente Juan Botet Escriba
_______________________________________________
Unsubscribe & other changes:
http://lists.boost.org/mailman/listinfo.cgi/boost
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk