Boost logo

Boost :

Subject: Re: [boost] [thread] Do we need thread_group now?
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2012-04-16 08:47:06

Vicente J. Botet 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();
> you are right for join_all and for c++11 compilers. But in
> order to make the code portable, join_all could help.

A newcomer to the library will not know what the correct formulation is to join all threads, or even that such a thing is possible or appropriate. There will be other variations than those you've shown for joining all threads in a container, which makes joining code less obvious. An algorithm provides a means to readable code, without variation, that immediately conveys the caller's intent. Add portability to the mix and providing join_all makes a lot of sense.

> 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.

Yet another reason to provide join_all: symmetry.

Rob Stewart robert.stewart_at_[hidden]
Software Engineer using std::disclaimer;
Dev Tools & Components
Susquehanna International Group, LLP


IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.

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