1 | // Copyright (C) 2010 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 2 |
7 | |
8 | #include <boost/thread/thread_only.hpp> |
9 | #include <boost/thread/future.hpp> |
10 | |
11 | int calculate_the_answer_to_life_the_universe_and_everything() |
12 | { |
13 | return 42; |
14 | } |
15 | |
16 | int main() { |
17 | boost::packaged_task<int> pt(calculate_the_answer_to_life_the_universe_and_everything); |
18 | |
19 | //boost::unique_future<int> fi = BOOST_THREAD_MAKE_RV_REF(pt.get_future()); |
20 | boost::unique_future<int> fi((BOOST_THREAD_MAKE_RV_REF(pt.get_future()))); |
21 | |
22 | boost::thread task(boost::move(t&: pt)); // launch task on a thread |
23 | |
24 | fi.wait(); // wait for it to finish |
25 | |
26 | //assert(fi.is_ready()); |
27 | //assert(fi.has_value()); |
28 | //assert(!fi.has_exception()); |
29 | //assert(fi.get_state()==boost::future_state::ready); |
30 | //assert(fi.get()==42); |
31 | } |
32 |