From: Giovanni Piero Deretta (gpderetta_at_[hidden])
Date: 2007-03-14 17:16:43


On 3/14/07, Peter Dimov <pdimov_at_[hidden]> wrote:
> Braddock Gaskill wrote:
>
> > So, that would mean that for f3 = f1 || f2, if f1 propagates an
> > exception while f2 succeeds, f3 still propagates an exception?
>
> I think that one sensible meaning of f1 || f2 is to wait until either one of
> f1 or f2 returns a value, or both fail.
>
> The "first to complete" approach is supported by my proposed future<>, but
> not in a composable way. You can hand the same future<> to two producers and
> the first one to place a value or an exception into it wins. But I haven't
> investigated the infrastructure that would allow operator||.
>
> As for operator&&, it doesn't deliver any extra functionality. Instead of
> wating for f1 && f2, you just wait for f1, then f2:
>
> future<int> f1 = fork( f, x );
> future<int> f2 = fork( f, y );
>
> std::cout << f1 + f2 << std::endl;
>
> There's no need to do:
>
> future< pair<int, int> > f3 = f1 && f2;
> pair<int,int> p = f3;
> std::cout << p.first + p.second << std::endl;
>

While there is no added functionality to being able to wait to two or
more futures at the same time, it could improve performance: the
waiting thread need to be awaken only once and you could save some
context switches.

gpd