[cpp-threads] Asynchronous Execution Issues (caching_async)

Boehm, Hans hans.boehm at hp.com
Mon May 4 17:55:39 BST 2009


> From:  Anthony Williams
> At Fri 01 May 2009 23:33:31 BST, Lawrence Crowl 
> <lawrence.crowl at gmail.com> wrote:
> 
> > On 5/1/09, Anthony Williams 
> 
> >> Also, people will expect detach().  Boost has it.  POSIX has it.
> >> Both have destructors for thread-locals.  This would be 
> seen as a big 
> >> step backwards.
> >
> > We need to ensure that C++0x can solve the problems for 
> which others 
> > used detach.  A careful analysis of examples might yield some 
> > interesting insights.
> 
> I support that in principle, but unless we make things 
> obvious and easy, people will complain about how C++0x lacks 
> obvious things like detached threads and simulate it with things like
> 
>     new thread(some_func); // deliberate leak for a detached thread
> 
I think that in the absence of a better solution to the problems associated with detach, this is an improvement.  By forcing a programmer to do this, we're forcing him/her to

- At least augment a subtle bug (race with static destructors) that would almost certainly be missed during testing, by one that would be reported by any leak detector.  (Alternatively, the new thread will be at least stored in a global as a result, which might put the actual correct code within reach.)

- Think about whether this code actually make sense, and perhaps find a discussion like this on the web that explains why it doesn't.

C++ inherently assumes that everything has a well-defined lifetime.  I just don't see a way to reconcile that with a thread whose lifetime you can't bound.  But it's certainly not too late for better, cleverer solutions ...

Hans


More information about the cpp-threads mailing list