From: Oliver Kullmann (O.Kullmann_at_[hidden])
Date: 2005-08-17 09:42:40
thanks for your reply.
> > Can one compute the short-circuit parallel or with your "futures" ?!
> The expression:
> int func1();
> int func2();
> future<int> f = int_[&func1] || int_[&func2];
> Creates a composite future (every of the functions is wrapped into a
> boost::thread), which when evaluated as
> int result = f();
> either returns immediately if one of the functions (func1 or func2) already
> did return, or blocks until one of the functions return. The return value of
> f() is the value returned from the function, which finished first.
> Is that what you've had in mind by mentioning 'shortcut evaluation'?
The problem here is, that the logical or can only be shortcircuit if one the
the operands is true, in which case the output is true; but if one of the function
returns false, then the return value is identical to the return value of the
To say it more precisely:
bool result = parallel_and_shortcircuit_or(f1, f2);
is needed, such that the following happens:
1) The evaluation of parallel_and_shortcircuit_or(f1, f2)
starts two independent threads for f1 and f2, and the main thread
2) As soon as f1 or f2 returns true, the following happens:
a) result is set to true, and the main thread continues;
b) say, f1 returned true: f2 then is cancelled (if still running),
and so does not waste computing resources anymore.
3) Otherwise, both threads have to be completed, and result is set to false.
Different to your solution above, we are happy with the evaluation of only
f1 or f2 only in the case the function returned true; and I guess, due to
the missing cancellation of threads, in your solution one thread will still
continue to run (and using resources) even if result has been computed and
the main thread is continuing, right?