Bram Neijt | 30 Aug 01:19

Opinion and help with implementing futures

Dear reader,

I've been wanting to implement a future in C++ for some time, and
combined some code to come up with the attached. The idea is that the
future is a function wrapper around a function call which will call the
function in a second thread upon creation. Then at a later moment, the
future can yield the return value of the wrapped function (or block
until this result is know).

I'm happy with the result I got so far. It's a very rough draft, and I
would like your help to clean up some details:
- I would like to have the Future wrapper work with the boost::function<
int (argument, argument)> syntax, but I can't figure out how to get the
return type from that syntax to allow for the return value to be defined
(the d_result member).
- What would be the best way to handle function arguments? Binding all
the parameters before passing the resulting bound function object seems
like the solution, but is it really the best solution?

And last but not least: has this already been done and what is the
general opinion within the boost community on having a class like this?

Greetings,
  Bram Neijt

Attached are two files, one is the Future class and the second is a test
program showing it's general functioning. The output of running the test
program should show:

Creating future
(Continue reading)

Edd Dawson | 30 Aug 11:45

Re: Opinion and help with implementing futures

On 30 Aug 2008, at 01:23, Bram Neijt wrote:

> Dear reader,
>
> I've been wanting to implement a future in C++ for some time, and
> combined some code to come up with the attached. The idea is that the
> future is a function wrapper around a function call which will call  
> the
> function in a second thread upon creation. Then at a later moment, the
> future can yield the return value of the wrapped function (or block
> until this result is know).
>
> I'm happy with the result I got so far. It's a very rough draft, and I
> would like your help to clean up some details:
> - I would like to have the Future wrapper work with the  
> boost::function<
> int (argument, argument)> syntax, but I can't figure out how to get  
> the
> return type from that syntax to allow for the return value to be  
> defined
> (the d_result member).

Is this really necessary? Once you have a future, you only care about  
its result, surely?

>
> - What would be the best way to handle function arguments? Binding all
> the parameters before passing the resulting bound function object  
> seems
> like the solution, but is it really the best solution?
(Continue reading)


Gmane