Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2003-02-08 11:28:55


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

> David Abrahams wrote:
>
>> That's the general idea. Of course we can haggle over the syntactic
>> details, but the main question is whether you can get a return value
>> from invoking a thread function or whether you have to declare some
>> "global" state and ask the thread function to modify it.
>
> 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();

    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));

-- 
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