Boost logo

Boost :

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


Le 09/10/15 15:02, Mikael Olenfalk a écrit :
> 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?
>>
>> Thanks,
>> Volodya
>>
>>
>>
> 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.
Right.
>
> I haven't really use this stuff, I have been playing with it in order to
> find out how to combine boost::asio::io_service and boost::future/async, to
> no avail sadly.
>
> /M
>
> [1] it is guarded by a macro which I cannot find in the docs:
> BOOST_THREAD_PROVIDES_EXECUTORS
Or BOOST_THREAD_VERSION 4
>
> [2]
> http://www.boost.org/doc/libs/1_59_0/doc/html/thread/synchronization.html#thread.synchronization.executors.ref.executor
>
> [3] the doc specify an overload then(Scheduler& S)
Could you point me where exactly you can fin this?

The doc says

template<typename S, typename F>
  |future|
<http://www.boost.org/doc/libs/1_59_0/doc/html/thread/synchronization.html#thread.synchronization.futures.reference.unique_future><typename boost::result_of<F(shared_future)>::type>
then(S& scheduler, F&& func) const; // EXTENSION

> but the code looks like
> this:
>
> #ifdef BOOST_THREAD_PROVIDES_EXECUTORS
> template<typename Ex, typename F>
> inline BOOST_THREAD_FUTURE<typename
> boost::result_of<F(BOOST_THREAD_FUTURE)>::type>
> then(Ex& ex, BOOST_THREAD_FWD_REF(F) func); // EXTENSION
> #endif

Vicente


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