1// Copyright (C) 2014 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#include <boost/config.hpp>
8#if ! defined BOOST_NO_CXX11_DECLTYPE
9#define BOOST_RESULT_OF_USE_DECLTYPE
10#endif
11
12#include <boost/thread/future.hpp>
13#include <boost/thread/thread.hpp>
14#include <thread>
15
16int main()
17{
18
19 {
20 boost::promise<int> promise;
21 boost::future<int> future = promise.get_future();
22
23 boost::future<int> result =
24 future.then
25 (
26 policy: boost::launch::deferred,
27 func: [](boost::future<int> && f)
28 {
29 std::cout << std::this_thread::get_id() << ": callback" << std::endl;
30 std::cout << "The value is: " << f.get() << std::endl;
31 return f.get();
32 }
33 );
34
35 // We could not reach here.
36 std::cout << std::this_thread::get_id() << ": function" << std::endl;
37
38 promise.set_value(0);
39 }
40
41 {
42 boost::promise<int> promise;
43 boost::shared_future<int> future = promise.get_future().share();
44
45 boost::future<int> result =
46 future.then
47 (
48 policy: boost::launch::deferred,
49 func: [](boost::shared_future<int> && f)
50 {
51 std::cout << std::this_thread::get_id() << ": callback" << std::endl;
52 std::cout << "The value is: " << f.get() << std::endl;
53 return f.get();
54 }
55 );
56
57 // We could not reach here.
58 std::cout << std::this_thread::get_id() << ": function" << std::endl;
59
60 promise.set_value(0);
61 }
62
63 return 0;
64}
65

source code of boost/libs/thread/test/test_11818.cpp