[cpp-threads] Asynchronous Function Proposal
Peter Dimov
pdimov at mmltd.net
Mon Jun 1 18:04:01 BST 2009
Herb Sutter:
>> - execute immediately (for generic contexts)
>
> Yes, but that is needed (only?) for testing and would be routinely
> provided as a QoI extension. No harm in providing it though.
This is handy when you want to e.g. limit the nested parallelism when
splitting recursively.
void f( int level, int n, ... )
{
async( level < 5 && n >= 10? default_policy: synchronous_policy, f,
level+1, n / 2, ... );
}
In this case you can just do an 'if', but more complicated examples might
have a function that determines the policy based on some criteria,
encapsulating the logic, or take a policy hint and modify it, and so on.
>> - defer until wait() is called (not get)
>
> I'm not opposed to including something like this, but I have seen no
> experience with it or need for something finer-grained than "execute
> immediately." Is there?
I'm not sure; this is just a "fixed" variant of Lawrence's deferred policy.
It might be useful for implementing a form of lazy evaluation. I remember a
boost::future proposal by Braddock Gaskill including such a capability.
More information about the cpp-threads
mailing list