1 | // Copyright (C) 2015 Vicente Botet |
---|---|
2 | // |
3 | // Distributed under the Boost Software License, Version 1.0. (See accompanying |
4 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
5 | |
6 | #define BOOST_THREAD_VERSION 4 |
7 | #define BOOST_THREAD_PROVIDES_EXECUTORS |
8 | |
9 | #include <boost/thread.hpp> |
10 | #include <boost/thread/thread_pool.hpp> |
11 | #include <cassert> |
12 | |
13 | auto createFuture() |
14 | { |
15 | boost::promise<void> promise; |
16 | promise.set_value(); |
17 | return promise.get_future(); |
18 | } |
19 | |
20 | auto stepOne(boost::basic_thread_pool &executor) |
21 | { |
22 | auto sendFuture = createFuture(); |
23 | auto wrappedFuture = sendFuture.then(ex&: executor, func: [](auto f) mutable { |
24 | return createFuture(); |
25 | }); |
26 | |
27 | return wrappedFuture.unwrap(); |
28 | } |
29 | |
30 | auto stepTwo(boost::basic_thread_pool &executor) |
31 | { |
32 | auto future = stepOne(executor); |
33 | return future.then(ex&: executor, func: [](auto f) { |
34 | assert(f.is_ready()); |
35 | }); |
36 | } |
37 | |
38 | int main() |
39 | { |
40 | boost::basic_thread_pool executor{1}; |
41 | stepTwo(executor).get(); |
42 | } |
43 |