Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r80756 - in trunk/libs/thread: example test
From: vicente.botet_at_[hidden]
Date: 2012-09-29 12:36:19


Author: viboes
Date: 2012-09-29 12:36:19 EDT (Sat, 29 Sep 2012)
New Revision: 80756
URL: http://svn.boost.org/trac/boost/changeset/80756

Log:
Thread: Added missing file
Added:
   trunk/libs/thread/example/make_future.cpp (contents, props changed)
Text files modified:
   trunk/libs/thread/test/Jamfile.v2 | 8 +++-----
   1 files changed, 3 insertions(+), 5 deletions(-)

Added: trunk/libs/thread/example/make_future.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/example/make_future.cpp 2012-09-29 12:36:19 EDT (Sat, 29 Sep 2012)
@@ -0,0 +1,42 @@
+// Copyright (C) 2012 Vicente Botet
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#define BOOST_THREAD_VERSION 4
+
+#include <boost/thread/future.hpp>
+#include <iostream>
+
+int p1() { return 5; }
+
+boost::future<int> compute(int x)
+{
+ if (x == 0) return boost::make_future(0);
+ if (x < 0) return boost::make_future(-1);
+ //boost::future<int> f1 = boost::async([]() { return x+1; });
+ boost::future<int> f1 = boost::async(p1);
+ return f1;
+}
+boost::shared_future<int> shared_compute(int x)
+{
+ if (x == 0) return boost::make_shared_future(0);
+ if (x < 0) return boost::make_shared_future(-1);
+ //boost::future<int> f1 = boost::async([]() { return x+1; });
+ boost::shared_future<int> f1 = boost::async(p1).share();
+ return f1;
+}
+
+
+int main()
+{
+ {
+ boost::future<int> f = compute(2);
+ std::cout << f.get() << std::endl;
+ }
+ {
+ boost::shared_future<int> f = shared_compute(2);
+ std::cout << f.get() << std::endl;
+ }
+ return 0;
+}

Modified: trunk/libs/thread/test/Jamfile.v2
==============================================================================
--- trunk/libs/thread/test/Jamfile.v2 (original)
+++ trunk/libs/thread/test/Jamfile.v2 2012-09-29 12:36:19 EDT (Sat, 29 Sep 2012)
@@ -509,6 +509,8 @@
           [ thread-run ../example/shared_mutex.cpp ]
           #[ thread-run ../example/vhh_shared_monitor.cpp ]
           #[ thread-run ../example/vhh_shared_mutex.cpp ]
+ [ thread-run ../example/make_future.cpp ]
+
     ;
 
     #explicit ts_shared_upwards ;
@@ -546,11 +548,7 @@
     explicit ts_ ;
     test-suite ts_
     :
- [ thread-run ../example/unwrap.cpp ]
- [ thread-run ../example/make_future.cpp ]
- [ thread-run2 ./sync/futures/packaged_task/dtor_pass.cpp : packaged_task__dtor_p2 ]
- [ thread-run2 ./sync/futures/future/get_pass.cpp : future__get_p2 ]
- [ thread-run2 ./sync/futures/packaged_task/operator_pass.cpp : packaged_task__operator_p2 ]
+ #[ thread-run ../example/unwrap.cpp ]
     ;
 
 }


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk