[cpp-threads] Asynchronous Execution Issues

Peter Dimov pdimov at mmltd.net
Sat Apr 25 13:10:22 BST 2009


Lawrence Crowl:
> Second, consider the case of the creating_async.  The problem here
> is a touch more subtle.  In particular, once the working thread has
> set its promise, it can start destroying thread-local variables.

Note that this is not limited to thread locals. If you execute

    X f();

with async, ~X will necessarily have to run after promise<X>::set_value( X 
const& x ).

> So, an asynchronous execution function needs another kind of future.

In principle, you don't need another future _type_. The futures are 
basically smart pointers to shared state. The state class can be 
polymorphic. You can create another future kind behind the scenes while 
still presenting the same interface to the user.

The timeouts will be off because you can't do timed joins so you'll have to 
make do with a timed wait followed by a join, and making is_ready 
nonblocking would be a challenge as well as there is no try_join either. 
I've argued that there should be, but it's hard to convince people unless 
they encounter the need themselves. :-) 




More information about the cpp-threads mailing list