Boost logo

Boost :

Subject: Re: [boost] [thread] boost::future::then
From: Mikael Olenfalk (mikael.olenfalk_at_[hidden])
Date: 2015-10-09 09:02:42


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.

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

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


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