~ubuntu-branches/ubuntu/wily/davix/wily

« back to all changes in this revision

Viewing changes to deps/boost_intern/src/thread/example/future_unwrap.cpp

  • Committer: Package Import Robot
  • Author(s): Mattias Ellert
  • Date: 2015-07-31 13:17:55 UTC
  • mfrom: (5.1.3 sid)
  • Revision ID: package-import@ubuntu.com-20150731131755-mizprbmn7ogv33te
Tags: 0.4.1-1
* Update to version 0.4.1
* Implement Multi-Arch support

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Copyright (C) 2012-2013 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_USES_LOG
8
 
#define BOOST_THREAD_USES_LOG_THREAD_ID
9
 
 
10
 
#include <boost/thread/detail/log.hpp>
11
 
#include <boost/thread/future.hpp>
12
 
#include <boost/assert.hpp>
13
 
#include <string>
14
 
#if defined BOOST_THREAD_PROVIDES_FUTURE_UNWRAP
15
 
 
16
 
int p1()
17
 
{
18
 
  BOOST_THREAD_LOG << "P1" << BOOST_THREAD_END_LOG;
19
 
  return 123;
20
 
}
21
 
 
22
 
boost::future<int> p2()
23
 
{
24
 
  BOOST_THREAD_LOG << "<P2" << BOOST_THREAD_END_LOG;
25
 
  boost::future<int> f1 = boost::async(boost::launch::async, &p1);
26
 
  BOOST_THREAD_LOG << "P2>" << BOOST_THREAD_END_LOG;
27
 
  return boost::move(f1);
28
 
}
29
 
 
30
 
int main()
31
 
{
32
 
  BOOST_THREAD_LOG << "<MAIN" << BOOST_THREAD_END_LOG;
33
 
  try
34
 
  {
35
 
    boost::future<boost::future<int> > outer_future = boost::async(boost::launch::async, &p2);
36
 
    boost::future<int> inner_future = outer_future.unwrap();
37
 
    int i = inner_future.get();
38
 
    BOOST_THREAD_LOG << "i= "<< i << "" << BOOST_THREAD_END_LOG;
39
 
  }
40
 
  catch (std::exception& ex)
41
 
  {
42
 
    BOOST_THREAD_LOG << "ERRORRRRR "<<ex.what() << "" << BOOST_THREAD_END_LOG;
43
 
    return 1;
44
 
  }
45
 
  catch (...)
46
 
  {
47
 
    BOOST_THREAD_LOG << " ERRORRRRR exception thrown" << BOOST_THREAD_END_LOG;
48
 
    return 2;
49
 
  }
50
 
  BOOST_THREAD_LOG << "MAIN>" << BOOST_THREAD_END_LOG;
51
 
  return 0;
52
 
}
53
 
#else
54
 
 
55
 
int main()
56
 
{
57
 
  return 0;
58
 
}
59
 
#endif