Boost logo

Boost :

Subject: Re: [boost] [thread] boost::future::then
From: Vicente J. Botet Escriba (vicente.botet_at_[hidden])
Date: 2015-10-09 15:49:52

Le 09/10/15 15:44, Vladimir Prus a écrit :
> On 09-Oct-15 4:02 PM, Mikael Olenfalk wrote:
>> On Fri, Oct 9, 2015 at 9:43 AM, Vladimir Prus <vladimir.prus_at_[hidden]>
>> wrote:
>>> In particular, suppose I have this:
>>> // Thread 1
>>> boost::promise<int> pi;
>>> boost::future<int> fi = pi.get_future();
>>> // pass pi to thread 2 somehow
>>> fi.then(....);
>>> // Thread 2
>>> pi.set_value(100);
>>> And I want continuation to be executed in thread 1, assuming that
>>> thread 1
>>> runs Qt event loop,
>>> allowing me to use QTimer::singleShot, or queued signal, or similar
>>> mechanism. How would I go
>>> about making boost::future do it? Has anybody done so?
> ...
>> I might have misunderstood the question but I would assume a solution
>> would
>> be to build boost.thread with executors enabled[1]. And then wrap the QT
>> event loop in an executor interface[2] and use the
>> boost::future<T>::then(Executor&, ...) overload.
> Mikael,
> thanks for the response. I suppose it would work - although if I need
> to pass this
> executor any time I call 'then', it become rather awkward rather quickly.
Well this is the current interface :)
> It would
> be nicer if promise could have an executor, and pass it to future and
> then
> to futures returned by 'then', so that I only need to to specify
> custom behaviour
> when creating a promise - that can be easily wrapped in a function.
If your future is created with
auto f = async(ex, fct)

then the call to


would use the same executor ex.

"When the scheduler or launch policy is not provided the continuation
inherits the parent's launch policy or scheduler. "

> Do you have any comments on presence or absence of bugs, and overall
> API maturity?
> Having to define macros to get useful functionality is not quite perfect.
I agree, but that is life. I have blocked the interface since version 3.
You must request any additional features explicitly if you want them, or
just say you want to use a higher version




Boost list run by bdawes at, gregod at, cpdaniel at, john at