--- In Boost-Users@y..., "giltayar"
1. On the multi-join/default constructor issue:
Hmmm... hadn't noticed the default ctor. The multi-join issue is a valid one. How I would solve it is for the dtor to "know" whether a join was called (using a private member), i.e. whether thread is alive or not, and thus know whether to join() it.
Yes, it's possible, but the semantics result in something that's at least a little surprising to some, and possibly not valid for others.
2. On the "leak":
How about this code:
void Foo (FooType& x) { MyFunction f(x); boost:thread t(f); // continue processing... if (error-occured-during-processing) throw std::exception("ouch"); // continue processing... t.join(); }
As a user of RIIA (resource-initialization-is-acquisition), this code would have looked apppropriate and OK. But it is wrong, because the thread may be accessing f, which will be out of scope in case the exception was thrown! To fix it, one should do...
No, it won't access an out of scope f. Why? Because the thread never accesses f at all. It uses a *copy* of f, whose lifetime will remain valid. In any case, you're describing a different problem from a "thread leak", and the above code simply won't "leak".
P.S. Am I re-hashing previous conversations? In this mailing list there is no searching capabilities, so I don't know.
Sure there's searching. Are you using the YahooGroups web interface? Bill Kempf