[cpp-threads] Asynchronous Execution Issues (caching_async)

Anthony Williams anthony at justsoftwaresolutions.co.uk
Sat May 2 20:25:00 BST 2009


At Fri 01 May 2009 23:33:31 BST, Lawrence Crowl  
<lawrence.crowl at gmail.com> wrote:

> On 5/1/09, Anthony Williams <anthony at justsoftwaresolutions.co.uk> wrote:
>> At Fri 01 May 2009 22:34:17 BST, "Boehm, Hans" <hans.boehm at hp.com> wrote:
>> > Here's a draft of a paper on these issues that Lawrence and I
>> > are about to submit.
>>
>> Sorry for my lack of reply earlier. I didn't see the messages
>> until now.
>>
>> I'm concerned about removing detach(). It makes it very hard
>> (if not impossible) to write a simple async function without
>> using a thread pool unless one also has a wait-for-the-thread
>> variant of a future. Even with a wait-for-the-thread future,
>> what happens if no-one waits? Do we get a thread leak? Join on
>> destruction? Throw on destruction?
>
> I would join on destruction, because I expect the destruction to
> happen without the wait mostly when the wait is bypassed by an
> exception, and I'd rather not put an exception in a destructor.

That is quite a change for futures. Currently you can discard a future  
if you don't need it. If you force a join in the destructor you have  
to wait for the async function to finish (thus making it synchronous  
rather than asynchronous) even if you no longer care about the result.  
Also, for a shared_future, which one has to wait depends on which is  
the last copy.

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

Anthony
-- 
Anthony Williams
Author of C++ Concurrency in Action | http://www.manning.com/williams
just::thread C++0x thread library   | http://www.stdthread.co.uk
Custom Software Development         | http://www.justsoftwaresolutions.co.uk
Just Software Solutions Ltd, Registered in England, Company Number 5478976.
Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK





More information about the cpp-threads mailing list