|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r80447 - trunk/libs/thread/test/sync/futures/async
From: vicente.botet_at_[hidden]
Date: 2012-09-08 10:16:07
Author: viboes
Date: 2012-09-08 10:16:07 EDT (Sat, 08 Sep 2012)
New Revision: 80447
URL: http://svn.boost.org/trac/boost/changeset/80447
Log:
Thread: test async with moveonly functors.
Text files modified:
trunk/libs/thread/test/sync/futures/async/async_pass.cpp | 64 ++++++++++++++++++++++++++++++++++++---
1 files changed, 59 insertions(+), 5 deletions(-)
Modified: trunk/libs/thread/test/sync/futures/async/async_pass.cpp
==============================================================================
--- trunk/libs/thread/test/sync/futures/async/async_pass.cpp (original)
+++ trunk/libs/thread/test/sync/futures/async/async_pass.cpp 2012-09-08 10:16:07 EDT (Sat, 08 Sep 2012)
@@ -33,6 +33,41 @@
typedef boost::chrono::high_resolution_clock Clock;
typedef boost::chrono::milliseconds ms;
+class A
+{
+ long data_;
+
+public:
+ typedef int result_type;
+
+ explicit A(long i) : data_(i) {}
+
+ long operator()() const
+ {
+ boost::this_thread::sleep_for(ms(200));
+ return data_;
+ }
+};
+
+class MoveOnly
+{
+public:
+ typedef int result_type;
+
+ BOOST_THREAD_MOVABLE_ONLY(MoveOnly)
+ MoveOnly()
+ {
+ }
+ MoveOnly(BOOST_THREAD_RV_REF(MoveOnly))
+ {}
+
+ int operator()()
+ {
+ boost::this_thread::sleep_for(ms(200));
+ return 3;
+ }
+};
+
int f0()
{
boost::this_thread::sleep_for(ms(200));
@@ -58,11 +93,14 @@
return boost::interprocess::unique_ptr<int, boost::default_delete<int> >(new int(i));
}
-//boost::interprocess::unique_ptr<int, boost::default_delete<int> > f4(boost::interprocess::unique_ptr<int, boost::default_delete<int> >&& p)
-//{
-// boost::this_thread::sleep_for(ms(200));
-// return boost::move(p);
-//}
+typedef boost::interprocess::unique_ptr<int, boost::default_delete<int> > XXT;
+boost::interprocess::unique_ptr<int, boost::default_delete<int> > f4(
+ BOOST_THREAD_RV_REF(boost::interprocess::unique_ptr<int, boost::default_delete<int> > ) p)
+{
+ boost::this_thread::sleep_for(ms(200));
+ return boost::move(p);
+}
+
int main()
{
@@ -83,6 +121,22 @@
BOOST_TEST(t1 - t0 < ms(100));
}
{
+ boost::future<int> f = boost::async(boost::launch::async, A(3));
+ boost::this_thread::sleep_for(ms(300));
+ Clock::time_point t0 = Clock::now();
+ BOOST_TEST(f.get() == 3);
+ Clock::time_point t1 = Clock::now();
+ BOOST_TEST(t1 - t0 < ms(100));
+ }
+ {
+ boost::future<int> f = boost::async(boost::launch::async, BOOST_THREAD_MAKE_RV_REF(MoveOnly()));
+ boost::this_thread::sleep_for(ms(300));
+ Clock::time_point t0 = Clock::now();
+ BOOST_TEST(f.get() == 3);
+ Clock::time_point t1 = Clock::now();
+ BOOST_TEST(t1 - t0 < ms(100));
+ }
+ {
boost::future<int> f = boost::async(boost::launch::any, f0);
boost::this_thread::sleep_for(ms(300));
Clock::time_point t0 = Clock::now();
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