Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r84589 - trunk/libs/thread/test
From: vicente.botet_at_[hidden]
Date: 2013-06-01 01:11:35


Author: viboes
Date: 2013-06-01 01:11:34 EDT (Sat, 01 Jun 2013)
New Revision: 84589
URL: http://svn.boost.org/trac/boost/changeset/84589

Log:
Thread: Added test for #8596.
Added:
   trunk/libs/thread/test/test_8596.cpp (contents, props changed)
Text files modified:
   trunk/libs/thread/test/Jamfile.v2 | 2 +-
   1 files changed, 1 insertions(+), 1 deletions(-)

Modified: trunk/libs/thread/test/Jamfile.v2
==============================================================================
--- trunk/libs/thread/test/Jamfile.v2 (original)
+++ trunk/libs/thread/test/Jamfile.v2 2013-06-01 01:11:34 EDT (Sat, 01 Jun 2013)
@@ -772,7 +772,7 @@
           #[ thread-run ../example/std_async_test.cpp ]
           #[ thread-run test_8508.cpp ]
           #[ thread-run test_8586.cpp ]
- #[ thread-run test_8596.cpp ]
+ [ thread-run test_8596.cpp ]
           #[ thread-run test_8600.cpp ]
           
     ;

Added: trunk/libs/thread/test/test_8596.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/test_8596.cpp 2013-06-01 01:11:34 EDT (Sat, 01 Jun 2013)
@@ -0,0 +1,38 @@
+// Copyright (C) 2013 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 <iostream>
+
+#include <boost/thread.hpp>
+#include <boost/shared_ptr.hpp>
+
+int f()
+{
+ return 42;
+}
+
+boost::packaged_task<int()>* schedule(boost::function<int ()> const& fn)
+{
+ // Normally, the pointer to the packaged task is stored in a queue
+ // for execution on a separate thread, and the schedule function
+ // would return just a future<T>
+
+ boost::function<int ()> copy(fn);
+ boost::packaged_task<int()>* result = new boost::packaged_task<int()>(copy);
+ return result;
+}
+
+int main()
+{
+ boost::packaged_task<int()>* p(schedule(f));
+ (*p)();
+
+ boost::future<int> fut = p->get_future();
+ std::cout << "The answer to the ultimate question: " << fut.get() << std::endl;
+
+ return 0;
+}


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