Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2003-02-08 12:56:12


"Peter Dimov" <pdimov_at_[hidden]> writes:

> David Abrahams wrote:
>> "Peter Dimov" <pdimov_at_[hidden]> writes:
>>
>>> With the above AsyncCall:
>>>
>>> async_call<int> f( bind(g, 1, 2) ); // can offer syntactic sugar here
>>> thread t(f); // or thread(f); for extra cuteness
>>> int r = f.result();
>>>
>>> The alternative seems to be
>>>
>>> async_call<int> f( bind(g, 1, 2) );
>>> int r = f.result();
>>>
>>> but now f is tied to boost::thread. A helper
>>>
>>> int r = async(g, 1, 2);
>>
>> Another alternative might allow all of the following:
>>
>> async_call<int> f(create_thread(), bind(g,1,2));
>> int r = f();
>>
>> async_call<int> f(thread_pool(), bind(g,1,2));
>> int r = f();
>
> Using an undefined-yet Executor concept for the first argument. This is not
> much different from
>
> async_call<int> f( bind(g, 1, 2) );
> // execute f using whatever Executor is appropriate
> int r = f.result();
>
> except that the async_call doesn't need to know about Executors.

...and that you don't need a special syntax to get the result out that
isn't compatible with functional programming. If you want to pass a
function object off from the above, you need something like:

    bind(&async_call<int>::result, async_call<int>(bind(g, 1, 2)))

>> int r = async_call<int>(create_thread(), bind(g, 1, 2));
>>
>> int r = async(boost::thread(), g, 1, 2);
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>>
>> int r = async_call<int>(rpc(some_machine), bind(g,1,2));
>>
>> int r = async_call<int>(my_message_queue, bind(g,1,2));
>
> All of these are possible with helper functions (and the <int> could be made
> optional.)

Yup, note the line in the middle.

> I've my doubts about
>
>> int r = async_call<int>(rpc(some_machine), bind(g,1,2));
>
> though. How do you envision this working? A local opaque function object
> can't be RPC'ed.

It would have to not be opaque ;-)

Maybe it's a wrapper over Python code that can be transmitted across
the wire. Anyway, I agree that it's not very likely. I just put it
in there to satisfy Bill, who seems to have some idea how RPC can be
squeezed into the same mold as thread invocation ;-)

> int r = rpc_call("g", 1, 2);
>
> looks much easier to implement.

Agreed.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk