]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/thread/test/test_12293.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / thread / test / test_12293.cpp
CommitLineData
7c673cae
FG
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
8// BoostFutureTest.cpp : Defines the entry point for the console application.
9//
10
11#include <iostream>
12
13// boost version 1.60.0
14// has the following set.
15#define BOOST_THREAD_VERSION 4
16// #define BOOST_THREAD_PROVIDES_EXECUTORS
17
18#include <boost/thread/future.hpp>
19
20
21int main()
22{
23 int value = 0;
24 int tmpValue = 0;
25 boost::promise<void> promise1;
26 boost::promise<void> promise2;
27
28 auto future1 = promise1.get_future();
29
30 auto waitFuture = future1.then([&tmpValue, &promise2](boost::future<void> future){
31 assert(future.is_ready()); // this works correctly and is ready.
32
33 auto fut = boost::async(boost::launch::async, [&promise2, &tmpValue](){
34 boost::this_thread::sleep_for(boost::chrono::seconds(1));
35 tmpValue = 1;
36 promise2.set_value();
37 std::cout << "Step 2 "<< std::endl; // should print 1 but prints 0
38 });
39 std::cout << "Step 1 "<< std::endl; // should print 1 but prints 0
40
41 return promise2.get_future();
42 //return ;
43 }).then([&value, &tmpValue](boost::future<boost::future<void>> future){
44 //}).then([&value, &tmpValue](boost::future<void> future){
45 // error: no matching function for call to ‘boost::future<boost::future<void> >::then(main()::<lambda(boost::future<void>)>)’
46 // as expected
47
48 assert(future.is_ready()); // this doesn't work correctly and is not ready.
49
50
51 value = tmpValue;
52 });
53
54
55 promise1.set_value();
56 waitFuture.wait();
57
58 std::cout << "value = " << value << std::endl; // should print 1 but prints 0
59 return 0;
60}
61