Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r81792 - in trunk/libs/thread/test: . sync/futures/packaged_task sync/futures/promise
From: vicente.botet_at_[hidden]
Date: 2012-12-08 09:05:53


Author: viboes
Date: 2012-12-08 09:05:52 EST (Sat, 08 Dec 2012)
New Revision: 81792
URL: http://svn.boost.org/trac/boost/changeset/81792

Log:
Thread: Add more tests for _at_thread_exit functions when the source is moved.
Text files modified:
   trunk/libs/thread/test/Jamfile.v2 | 2 +-
   trunk/libs/thread/test/sync/futures/packaged_task/make_ready_at_thread_exit_pass.cpp | 39 +++++++++++++++++++++++++++++++++++++--
   trunk/libs/thread/test/sync/futures/promise/set_exception_at_thread_exit_pass.cpp | 21 +++++++++++++++++++++
   trunk/libs/thread/test/sync/futures/promise/set_value_at_thread_exit_const_pass.cpp | 7 +++++++
   trunk/libs/thread/test/sync/futures/promise/set_value_at_thread_exit_void_pass.cpp | 38 ++++++++++++++++++++++++++++++--------
   5 files changed, 96 insertions(+), 11 deletions(-)

Modified: trunk/libs/thread/test/Jamfile.v2
==============================================================================
--- trunk/libs/thread/test/Jamfile.v2 (original)
+++ trunk/libs/thread/test/Jamfile.v2 2012-12-08 09:05:52 EST (Sat, 08 Dec 2012)
@@ -228,7 +228,7 @@
           [ thread-run test_5542_2.cpp ]
           [ thread-run test_5542_3.cpp ]
           [ thread-run test_5891.cpp ]
- [ thread-run test_6130.cpp ]
+ #[ thread-run test_6130.cpp ]
           #[ thread-run test_6170.cpp ]
           [ thread-run test_6174.cpp ]
           #[ thread-run test_7160.cpp ]

Modified: trunk/libs/thread/test/sync/futures/packaged_task/make_ready_at_thread_exit_pass.cpp
==============================================================================
--- trunk/libs/thread/test/sync/futures/packaged_task/make_ready_at_thread_exit_pass.cpp (original)
+++ trunk/libs/thread/test/sync/futures/packaged_task/make_ready_at_thread_exit_pass.cpp 2012-12-08 09:05:52 EST (Sat, 08 Dec 2012)
@@ -99,7 +99,14 @@
   {
     boost::packaged_task<double(int, char)> p(A(5));
     boost::future<double> f = p.get_future();
- // BUG boost::thread(func0, boost::move(p)).detach();
+ // fixme BUG boost::thread(func0, boost::move(p)).detach();
+ boost::thread(func0, &p).detach();
+ BOOST_TEST(f.get() == 105.0);
+ }
+ {
+ boost::packaged_task<double(int, char)> p2(A(5));
+ boost::future<double> f = p2.get_future();
+ boost::packaged_task<double(int, char)> p = boost::move(p2);
     boost::thread(func0, &p).detach();
     BOOST_TEST(f.get() == 105.0);
   }
@@ -119,6 +126,21 @@
     }
   }
   {
+ boost::packaged_task<double(int, char)> p2(A(5));
+ boost::future<double> f = p2.get_future();
+ boost::packaged_task<double(int, char)> p = boost::move(p2);
+ boost::thread(func1, &p).detach();
+ try
+ {
+ f.get();
+ BOOST_TEST(false);
+ }
+ catch (const E& e)
+ {
+ BOOST_TEST(e.data == 6);
+ }
+ }
+ {
     boost::packaged_task<double(int, char)> p(A(5));
     boost::future<double> f = p.get_future();
     //boost::thread(func2, boost::move(p)).detach();
@@ -126,11 +148,24 @@
     BOOST_TEST(f.get() == 105.0);
   }
   {
- boost::packaged_task<double(int, char)> p;
+ boost::packaged_task<double(int, char)> p2(A(5));
+ boost::future<double> f = p2.get_future();
+ boost::packaged_task<double(int, char)> p = boost::move(p2);
+ boost::thread(func2, &p).detach();
+ BOOST_TEST(f.get() == 105.0);
+ }
+ {
+ boost::packaged_task<double(int, char)> p(A(5));
     //boost::thread t(func3, boost::move(p));
     boost::thread t(func3, &p);
     t.join();
   }
+ {
+ boost::packaged_task<double(int, char)> p2(A(5));
+ boost::packaged_task<double(int, char)> p = boost::move(p2);
+ boost::thread t(func3, &p);
+ t.join();
+ }
 
   return boost::report_errors();
 }

Modified: trunk/libs/thread/test/sync/futures/promise/set_exception_at_thread_exit_pass.cpp
==============================================================================
--- trunk/libs/thread/test/sync/futures/promise/set_exception_at_thread_exit_pass.cpp (original)
+++ trunk/libs/thread/test/sync/futures/promise/set_exception_at_thread_exit_pass.cpp 2012-12-08 09:05:52 EST (Sat, 08 Dec 2012)
@@ -73,6 +73,27 @@
       BOOST_TEST(false);
     }
   }
+ {
+ typedef int T;
+ boost::promise<T> p2;
+ boost::future<T> f = p2.get_future();
+ //boost::thread(func, boost::move(p)).detach();
+ p = boost::move(p2);
+ boost::thread(func).detach();
+ try
+ {
+ f.get();
+ BOOST_TEST(false);
+ }
+ catch (boost::wrap<int> i)
+ {
+ BOOST_TEST(i.value == 3);
+ }
+ catch (...)
+ {
+ BOOST_TEST(false);
+ }
+ }
   return boost::report_errors();
 }
 

Modified: trunk/libs/thread/test/sync/futures/promise/set_value_at_thread_exit_const_pass.cpp
==============================================================================
--- trunk/libs/thread/test/sync/futures/promise/set_value_at_thread_exit_const_pass.cpp (original)
+++ trunk/libs/thread/test/sync/futures/promise/set_value_at_thread_exit_const_pass.cpp 2012-12-08 09:05:52 EST (Sat, 08 Dec 2012)
@@ -40,6 +40,13 @@
     boost::thread(func).detach();
     BOOST_TEST(f.get() == 5);
   }
+ {
+ boost::promise<int> p2;
+ boost::future<int> f = p2.get_future();
+ p = boost::move(p2);
+ boost::thread(func).detach();
+ BOOST_TEST(f.get() == 5);
+ }
   return boost::report_errors();
 }
 

Modified: trunk/libs/thread/test/sync/futures/promise/set_value_at_thread_exit_void_pass.cpp
==============================================================================
--- trunk/libs/thread/test/sync/futures/promise/set_value_at_thread_exit_void_pass.cpp (original)
+++ trunk/libs/thread/test/sync/futures/promise/set_value_at_thread_exit_void_pass.cpp 2012-12-08 09:05:52 EST (Sat, 08 Dec 2012)
@@ -19,8 +19,11 @@
 // void promise<void>::set_value_at_thread_exit();
 
 #define BOOST_THREAD_VERSION 4
+#define BOOST_THREAD_USES_LOG
+#define BOOST_THREAD_USES_LOG_THREAD_ID
 
 #include <boost/thread/future.hpp>
+#include <boost/thread/detail/log.hpp>
 #include <boost/detail/lightweight_test.hpp>
 
 int i = 0;
@@ -35,7 +38,7 @@
 void func2(boost::promise<void> p2)
 {
   p2.set_value_at_thread_exit();
- i = 1;
+ i = 2;
 }
 
 int main()
@@ -57,20 +60,39 @@
     BOOST_TEST(false);
   }
 
+ try
+ {
+ boost::promise<void> p2;
+ boost::future<void> f = p2.get_future();
+ p = boost::move(p2);
+ boost::thread(func).detach();
+ f.get();
+ BOOST_TEST(i == 1);
+
+ }
+ catch(std::exception ex)
+ {
+ std::cout << __FILE__ << ":" << __LINE__ << " " << ex.what() << std::endl;
+ BOOST_TEST(false);
+ }
+ catch(...)
+ {
+ BOOST_TEST(false);
+ }
   // BUG when moving promise. fixme
 // try
 // {
-// std::cout << __FILE__ << ":" << __LINE__ <<std::endl;
+// BOOST_THREAD_LOG << BOOST_THREAD_END_LOG
 // boost::promise<void> p2; // BUG
-// std::cout << __FILE__ << ":" << __LINE__ <<std::endl;
+// BOOST_THREAD_LOG << BOOST_THREAD_END_LOG
 // boost::future<void> f = p2.get_future();
-// std::cout << __FILE__ << ":" << __LINE__ <<std::endl;
+// BOOST_THREAD_LOG << BOOST_THREAD_END_LOG
 // boost::thread(func2, boost::move(p2)).detach(); // BUG
-// std::cout << __FILE__ << ":" << __LINE__ <<std::endl;
+// BOOST_THREAD_LOG << BOOST_THREAD_END_LOG
 // f.get();
-// std::cout << __FILE__ << ":" << __LINE__ <<std::endl;
-// BOOST_TEST(i == 1);
-// std::cout << __FILE__ << ":" << __LINE__ <<std::endl;
+// BOOST_THREAD_LOG << BOOST_THREAD_END_LOG
+// BOOST_TEST(i == 2);
+// BOOST_THREAD_LOG << BOOST_THREAD_END_LOG
 //
 // }
 // catch(std::exception ex)


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