Le 09/10/15 15:02, Mikael Olenfalk a écrit :
On Fri, Oct 9, 2015 at 9:43 AM, Vladimir Prus
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#th...
[3] the doc specify an overload then(Scheduler& S) Could you point me where exactly you can fin this?
The doc says
template
but the code looks like this:
#ifdef BOOST_THREAD_PROVIDES_EXECUTORS template
inline BOOST_THREAD_FUTURE ::type> then(Ex& ex, BOOST_THREAD_FWD_REF(F) func); // EXTENSION #endif
Vicente