
On Sat, Apr 14, 2012 at 2:28 AM, Vicente J. Botet Escriba < vicente.botet@wanadoo.fr> wrote:
Le 14/04/12 01:12, Howard Hinnant a écrit :
On Apr 10, 2012, at 1:32 PM, Vicente J. Botet Escriba wrote:
join_all(threads);
Is it worth the electrons to turn this into an algorithm?
std::for_each(threads.begin(), threads.end(), [](thread& t) {t.join();});
or even simpler (really I think std::for_each is probably obsolete):
for (auto& t : threads) t.join();
Hi Howard,
you are right for join_all and for c++11 compilers. But in order to make the code portable, join_all could help.
In addition, Boost.Thread provides timed join functions and I suspect that joining N threads for a given duration is less evident and subject to error on the user side.
template <typename TC, typename C, typename D> bool try_join_all_until(TC & cont, chrono::time_point<C,D> const& tp) { for (auto& t : cont) { if (! t.try_join_until(d, tp)) return false; } return true; }
Or a better way to do it.
template <typename TC, typename R, typename P> bool try_join_all_for(TC & cont, chrono::duration<R,P> const& d) { chrono::steady_clock::time_**point tp = chrono::steady_clock::now()+d; return try_join_all_until(cont, tp); }
I don't know it adding these simple algorithms would be useful to the Boost community if thread_group is deprecated. I could live without them, my main concern is to deprecate thread_group.
What do you and others think? Anthony?
If a boost::container::vector (or whatever) of boost::thread's (with a set of algorithms as free functions, e.g., join_all) can function essentially the same as boost::thread_group, then I think that makes sense. - Jeff