[cpp-threads] Re: Thread API interface tweaks
Doug Lea
dl at cs.oswego.edu
Wed Aug 30 12:51:44 BST 2006
Peter Dimov wrote:
>
>
> Does a Java Future<V> provide the "multiple OR wait" capability? That
> is, can I wait for f1 or f2 to complete?
We don't currently do this using Futures per se because
there are several plausible semantics people might want here --
invokeAny style, where you cancel others once one completes
invokeAll style, where you let all complete and then return list
mapReduce-style, where the external get() somehow reduces multiple results
The little utility that makes these pretty easy (once you get used to it)
is ExecutorCompletionService.
http://gee.cs.oswego.edu/dl/jsr166/dist/docs/java/util/concurrent/ExecutorCompletionService.html
For convenience we also pre-wire the two common cases of invokeAll and
invokeAny in ExecutorService.
But we are in the midst of putting together for next release
a small suite of loop-parallelization aids that use lighter-weight
variants to support applyToAll, map, mapReduce, etc on Collections.
Each of these is likely to return something conforming to interface
Future. This generally works out OK so far, but in some cases people
may still prefer a completion-service-style API where they can get at
results one-by-one as they are ready.
>
> Multiple waits aside, I believe that my proposed future<>, task<> and
> Executor match the Java concepts pretty closely.
I think you are right.
-Doug
More information about the cpp-threads
mailing list