Boost logo

Boost :

From: vicente.botet (vicente.botet_at_[hidden])
Date: 2008-05-14 05:59:37


----- Original Message -----
From: "Anthony Williams" <anthony_w.geo_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Wednesday, May 14, 2008 10:55 AM
Subject: Re: [boost] Review Request: future library (N2561/Williams version)

> "vicente.botet" <vicente.botet_at_[hidden]> writes:
>
>> Why you don't allow multiple callbacks? I suposse that this is related to
>> the implementation of do_callback
>>
>> void do_callback(boost::unique_lock<boost::mutex>& lock)
>> {
>> if(callback && !done)
>> {
>> boost::function<void()> local_callback=callback;
>> relocker relock(lock);
>> local_callback();
>> }
>> }
>>
>> You need to call all the callbacks with the mutex unlock, and you need to
>> protect from other concurrent set_wait_callback. So you will need to copy
>> the list of callbacks before unlock.
>>
>> Is this correct?
>
> That is correct with respect to the implementation,

BTW, Braddock implementation do a move of the list of callbacks before doing
the callbacks. What do you thing about this approach?

> but I don't actually see
> the need for multiple callbacks. The callbacks are set as part of the
> promise
> or packaged_task. I can't imagine why that would require multiple
> callbacks. In any case, the user can provide that facility on their own if
> required.
>

What about the guarded schedule of Braddock?
    template future<T>
    schedule(boost::function<T (void)> const& fn, future<void> guard =
future<void>()) {
         promise<T> prom; // create promise
         future_wrapper<T> wrap(fn,prom);
         guard.add_callback(boost::bind(&JobQueue3::queueWrapped<T>, this,
wrap, prom));
         return future<T>(prom); // return a future created from the promise
    }

Several task can be scheduled guarded by the same future.

Vicente


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