Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r62135 - in sandbox/chrono/libs/thread: build test
From: vicente.botet_at_[hidden]
Date: 2010-05-21 20:37:24


Author: viboes
Date: 2010-05-21 20:37:21 EDT (Fri, 21 May 2010)
New Revision: 62135
URL: http://svn.boost.org/trac/boost/changeset/62135

Log:
Boost.Chrono 0.5:
* Update some test in Boost.Thread to test the use of Boost.Chrono

Text files modified:
   sandbox/chrono/libs/thread/build/Jamfile.v2 | 6 +
   sandbox/chrono/libs/thread/test/Jamfile.v2 | 24 +++-
   sandbox/chrono/libs/thread/test/condition_test_common.hpp | 29 +++++
   sandbox/chrono/libs/thread/test/test_condition_notify_all.cpp | 29 +++++
   sandbox/chrono/libs/thread/test/test_futures.cpp | 41 +++++++-
   sandbox/chrono/libs/thread/test/test_lock_concept.cpp | 8 +
   sandbox/chrono/libs/thread/test/test_mutex.cpp | 74 ++++++++++++--
   sandbox/chrono/libs/thread/test/test_shared_mutex_timed_locks.cpp | 190 ++++++++++++++++++++++++++++++---------
   sandbox/chrono/libs/thread/test/test_thread.cpp | 13 ++
   9 files changed, 335 insertions(+), 79 deletions(-)

Modified: sandbox/chrono/libs/thread/build/Jamfile.v2
==============================================================================
--- sandbox/chrono/libs/thread/build/Jamfile.v2 (original)
+++ sandbox/chrono/libs/thread/build/Jamfile.v2 2010-05-21 20:37:21 EDT (Fri, 21 May 2010)
@@ -39,10 +39,16 @@
 project boost/thread
     : source-location ../src
     : requirements <threading>multi
+ <library>/boost/system//boost_system
+ <library>/boost/chrono//boost_chrono
       <link>static:<define>BOOST_THREAD_BUILD_LIB=1
       <link>shared:<define>BOOST_THREAD_BUILD_DLL=1
       -<tag>@$(BOOST_JAMROOT_MODULE)%$(BOOST_JAMROOT_MODULE).tag
       <tag>@$(__name__).tag
+# : usage-requirements # pass these requirement to dependents (i.e. users)
+# <threading>multi
+# <library>/boost/system//boost_system
+# <library>/boost/chrono//boost_chrono
     : default-build <threading>multi
     ;
 

Modified: sandbox/chrono/libs/thread/test/Jamfile.v2
==============================================================================
--- sandbox/chrono/libs/thread/test/Jamfile.v2 (original)
+++ sandbox/chrono/libs/thread/test/Jamfile.v2 2010-05-21 20:37:21 EDT (Fri, 21 May 2010)
@@ -1,6 +1,6 @@
-# (C) Copyright William E. Kempf 2001.
-# (C) Copyright 2007 Anthony Williams.
-# Distributed under the Boost Software License, Version 1.0. (See accompanying
+# (C) Copyright William E. Kempf 2001.
+# (C) Copyright 2007 Anthony Williams.
+# 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)
 #
 # Boost.Threads test Jamfile
@@ -21,16 +21,21 @@
 project
     : requirements <library>/boost/test//boost_unit_test_framework/<link>static
                    <threading>multi
+ #<define>BOOST_THREAD_TEST_CHRONO
+ #<library>/boost/system//boost_system <library>/boost/chrono//boost_chrono
     ;
 
 rule thread-run ( sources )
 {
- return
+ return
     [ run $(sources) ../build//boost_thread ]
- [ run $(sources) ../src/tss_null.cpp ../build//boost_thread/<link>static
+ [ run $(sources) ../src/tss_null.cpp ../build//boost_thread/<link>static
         : : : : $(sources[1]:B)_lib ]
+ [ run $(sources) ../build//boost_thread : : : <library>/boost/system//boost_system <library>/boost/chrono//boost_chrono : $(sources[1]:B)_chrono ]
+ [ run $(sources) ../src/tss_null.cpp ../build//boost_thread/<link>static
+ : : : <library>/boost/system//boost_system/<link>static <library>/boost/chrono//boost_chrono/<link>static : $(sources[1]:B)_chronolib ]
     ;
-}
+}
 
 {
     test-suite "threads"
@@ -38,8 +43,8 @@
           [ thread-run test_thread_id.cpp ]
           [ thread-run test_hardware_concurrency.cpp ]
           [ thread-run test_thread_move.cpp ]
- [ thread-run test_thread_return_local.cpp ]
- [ thread-run test_thread_move_return.cpp ]
+ #[ thread-run test_thread_return_local.cpp ]
+ #[ thread-run test_thread_move_return.cpp ]
           [ thread-run test_thread_launching.cpp ]
           [ thread-run test_thread_mf.cpp ]
           [ thread-run test_thread_exit.cpp ]
@@ -62,4 +67,7 @@
           [ compile-fail no_implicit_move_from_lvalue_thread.cpp ]
           [ compile-fail no_implicit_assign_from_lvalue_thread.cpp ]
     ;
+
+
+
 }

Modified: sandbox/chrono/libs/thread/test/condition_test_common.hpp
==============================================================================
--- sandbox/chrono/libs/thread/test/condition_test_common.hpp (original)
+++ sandbox/chrono/libs/thread/test/condition_test_common.hpp 2010-05-21 20:37:21 EDT (Fri, 21 May 2010)
@@ -9,6 +9,17 @@
 #include <boost/thread/mutex.hpp>
 #include <boost/thread/thread_time.hpp>
 
+#ifdef BOOST_THREAD_TEST_CHRONO
+ using namespace boost::chrono;
+ typedef system_clock::time_point system_time_point;
+ system_time_point now() {return system_clock::now();}
+#else
+ using namespace boost::posix_time;
+ typedef boost::system_time system_time_point;
+ system_time_point now() {return boost::get_system_time();}
+#endif
+
+
 unsigned const timeout_seconds=5;
     
 struct wait_for_flag
@@ -61,12 +72,16 @@
 
     void timed_wait_without_predicate()
     {
- boost::system_time const timeout=boost::get_system_time()+boost::posix_time::seconds(timeout_seconds);
+ system_time_point const timeout=now()+seconds(timeout_seconds);
             
         boost::mutex::scoped_lock lock(mutex);
         while(!flag)
         {
+#ifdef BOOST_THREAD_TEST_CHRONO
+ if(!cond_var.wait_until(lock,timeout))
+#else
             if(!cond_var.timed_wait(lock,timeout))
+#endif
             {
                 return;
             }
@@ -76,9 +91,13 @@
 
     void timed_wait_with_predicate()
     {
- boost::system_time const timeout=boost::get_system_time()+boost::posix_time::seconds(timeout_seconds);
+ system_time_point const timeout=now()+seconds(timeout_seconds);
         boost::mutex::scoped_lock lock(mutex);
+#ifdef BOOST_THREAD_TEST_CHRONO
+ if(cond_var.wait_until(lock,timeout,check_flag(flag)) && flag)
+#else
         if(cond_var.timed_wait(lock,timeout,check_flag(flag)) && flag)
+#endif
         {
             ++woken;
         }
@@ -86,7 +105,11 @@
     void relative_timed_wait_with_predicate()
     {
         boost::mutex::scoped_lock lock(mutex);
- if(cond_var.timed_wait(lock,boost::posix_time::seconds(timeout_seconds),check_flag(flag)) && flag)
+#ifdef BOOST_THREAD_TEST_CHRONO
+ if(cond_var.wait_for(lock,seconds(timeout_seconds),check_flag(flag)) && flag)
+#else
+ if(cond_var.timed_wait(lock,seconds(timeout_seconds),check_flag(flag)) && flag)
+#endif
         {
             ++woken;
         }

Modified: sandbox/chrono/libs/thread/test/test_condition_notify_all.cpp
==============================================================================
--- sandbox/chrono/libs/thread/test/test_condition_notify_all.cpp (original)
+++ sandbox/chrono/libs/thread/test/test_condition_notify_all.cpp 2010-05-21 20:37:21 EDT (Fri, 21 May 2010)
@@ -200,13 +200,33 @@
     thread3.join();
 }
 
-void test_condition_notify_all()
+void test_condition_notify_all_wakes_from_wait()
 {
     timed_test(&do_test_condition_notify_all_wakes_from_wait, timeout_seconds);
+}
+
+void test_condition_notify_all_wakes_from_wait_with_predicate()
+{
     timed_test(&do_test_condition_notify_all_wakes_from_wait_with_predicate, timeout_seconds);
+}
+
+void test_condition_notify_all_wakes_from_timed_wait()
+{
     timed_test(&do_test_condition_notify_all_wakes_from_timed_wait, timeout_seconds);
+}
+
+void test_condition_notify_all_wakes_from_timed_wait_with_predicate()
+{
     timed_test(&do_test_condition_notify_all_wakes_from_timed_wait_with_predicate, timeout_seconds);
+}
+
+void test_condition_notify_all_wakes_from_relative_timed_wait_with_predicate()
+{
     timed_test(&do_test_condition_notify_all_wakes_from_relative_timed_wait_with_predicate, timeout_seconds);
+}
+
+void test_notify_all_following_notify_one_wakes_all_threads()
+{
     timed_test(&do_test_notify_all_following_notify_one_wakes_all_threads, timeout_seconds);
 }
 
@@ -216,7 +236,12 @@
     boost::unit_test_framework::test_suite* test =
         BOOST_TEST_SUITE("Boost.Threads: condition test suite");
 
- test->add(BOOST_TEST_CASE(&test_condition_notify_all));
+ test->add(BOOST_TEST_CASE(&test_condition_notify_all_wakes_from_wait));
+ test->add(BOOST_TEST_CASE(&test_condition_notify_all_wakes_from_wait_with_predicate));
+ test->add(BOOST_TEST_CASE(&test_condition_notify_all_wakes_from_timed_wait));
+ test->add(BOOST_TEST_CASE(&test_condition_notify_all_wakes_from_timed_wait_with_predicate));
+ test->add(BOOST_TEST_CASE(&test_condition_notify_all_wakes_from_relative_timed_wait_with_predicate));
+ test->add(BOOST_TEST_CASE(&test_notify_all_following_notify_one_wakes_all_threads));
 
     return test;
 }

Modified: sandbox/chrono/libs/thread/test/test_futures.cpp
==============================================================================
--- sandbox/chrono/libs/thread/test/test_futures.cpp (original)
+++ sandbox/chrono/libs/thread/test/test_futures.cpp 2010-05-21 20:37:21 EDT (Fri, 21 May 2010)
@@ -14,6 +14,17 @@
 
 #include <boost/test/unit_test.hpp>
 
+#ifdef BOOST_THREAD_TEST_CHRONO
+ using namespace boost::chrono;
+ typedef system_clock::time_point system_time_point;
+ system_time_point now() {return system_clock::now();}
+#else
+ using namespace boost::posix_time;
+ typedef boost::system_time system_time_point;
+ system_time_point now() {return boost::get_system_time();}
+#endif
+
+
 #ifndef BOOST_NO_RVALUE_REFERENCES
     template<typename T>
     typename boost::remove_reference<T>::type&& cast_to_rval(T&& t)
@@ -582,16 +593,32 @@
     boost::promise<int> pi;
     boost::unique_future<int> fi=pi.get_future();
     pi.set_wait_callback(do_nothing_callback);
- bool success=fi.timed_wait(boost::posix_time::milliseconds(10));
+#ifdef BOOST_THREAD_TEST_CHRONO
+ bool success=fi.wait_for(milliseconds(10));
+#else
+ bool success=fi.timed_wait(milliseconds(10));
+#endif
     BOOST_CHECK(callback_called);
     BOOST_CHECK(!success);
- success=fi.timed_wait(boost::posix_time::milliseconds(10));
+#ifdef BOOST_THREAD_TEST_CHRONO
+ success=fi.wait_for(milliseconds(10));
+#else
+ success=fi.timed_wait(milliseconds(10));
+#endif
     BOOST_CHECK(!success);
- success=fi.timed_wait(boost::posix_time::milliseconds(10));
+#ifdef BOOST_THREAD_TEST_CHRONO
+ success=fi.wait_for(milliseconds(10));
+#else
+ success=fi.timed_wait(milliseconds(10));
+#endif
     BOOST_CHECK(!success);
     BOOST_CHECK(callback_called==3);
     pi.set_value(42);
- success=fi.timed_wait(boost::posix_time::milliseconds(10));
+#ifdef BOOST_THREAD_TEST_CHRONO
+ success=fi.wait_for(milliseconds(10));
+#else
+ success=fi.timed_wait(milliseconds(10));
+#endif
     BOOST_CHECK(success);
     BOOST_CHECK(callback_called==3);
     BOOST_CHECK(fi.get()==42);
@@ -694,7 +721,11 @@
 
 int make_int_slowly()
 {
- boost::this_thread::sleep(boost::posix_time::seconds(1));
+#ifdef BOOST_THREAD_TEST_CHRONO
+ boost::this_thread::sleep_for(seconds(1));
+#else
+ boost::this_thread::sleep(seconds(1));
+#endif
     return 42;
 }
 

Modified: sandbox/chrono/libs/thread/test/test_lock_concept.cpp
==============================================================================
--- sandbox/chrono/libs/thread/test/test_lock_concept.cpp (original)
+++ sandbox/chrono/libs/thread/test/test_lock_concept.cpp 2010-05-21 20:37:21 EDT (Fri, 21 May 2010)
@@ -540,9 +540,17 @@
     BOOST_CHECK(dummy.shared_locked);
     lk.unlock();
     BOOST_CHECK(dummy.shared_unlocked);
+#ifdef BOOST_THREAD_TEST_CHRONO
+ lk.try_lock_for(boost::chrono::milliseconds(5));
+#else
     lk.timed_lock(boost::posix_time::milliseconds(5));
+#endif
     BOOST_CHECK(dummy.shared_timed_locked_relative);
+#ifdef BOOST_THREAD_TEST_CHRONO
+ lk.try_lock_until(boost::chrono::system_clock::now());
+#else
     lk.timed_lock(boost::get_system_time());
+#endif
     BOOST_CHECK(dummy.shared_timed_locked_absolute);
 }
 

Modified: sandbox/chrono/libs/thread/test/test_mutex.cpp
==============================================================================
--- sandbox/chrono/libs/thread/test/test_mutex.cpp (original)
+++ sandbox/chrono/libs/thread/test/test_mutex.cpp 2010-05-21 20:37:21 EDT (Fri, 21 May 2010)
@@ -17,6 +17,16 @@
 #define DEFAULT_EXECUTION_MONITOR_TYPE execution_monitor::use_sleep_only
 #include <libs/thread/test/util.inl>
 
+#ifdef BOOST_THREAD_TEST_CHRONO
+ using namespace boost::chrono;
+ typedef system_clock::time_point system_time_point;
+ system_time_point now() {return system_clock::now();}
+#else
+ using namespace boost::posix_time;
+ typedef boost::system_time system_time_point;
+ system_time_point now() {return boost::get_system_time();}
+#endif
+
 template <typename M>
 struct test_lock
 {
@@ -36,6 +46,12 @@
         lock_type lock(mutex);
         BOOST_CHECK(lock ? true : false);
 
+#ifdef BOOST_THREAD_TEST_CHRONO
+ // Test the lock and the mutex with condition variables.
+ // No one is going to notify this condition variable. We expect to
+ // time out.
+ BOOST_CHECK(!condition.wait_for(lock, milliseconds(100)));
+#else
         // Construct and initialize an xtime for a fast time out.
         boost::xtime xt = delay(0, 100);
 
@@ -43,8 +59,9 @@
         // No one is going to notify this condition variable. We expect to
         // time out.
         BOOST_CHECK(!condition.timed_wait(lock, xt));
+#endif
         BOOST_CHECK(lock ? true : false);
-
+
         // Test the lock and unlock methods.
         lock.unlock();
         BOOST_CHECK(!lock);
@@ -76,6 +93,9 @@
         try_lock_type lock(mutex);
         BOOST_CHECK(lock ? true : false);
 
+#ifdef BOOST_THREAD_TEST_CHRONO
+ BOOST_CHECK(!condition.wait_for(lock, milliseconds(100)));
+#else
         // Construct and initialize an xtime for a fast time out.
         boost::xtime xt = delay(0, 100);
 
@@ -83,6 +103,7 @@
         // No one is going to notify this condition variable. We expect to
         // time out.
         BOOST_CHECK(!condition.timed_wait(lock, xt));
+#endif
         BOOST_CHECK(lock ? true : false);
 
         // Test the lock, unlock and trylock methods.
@@ -115,7 +136,11 @@
     void locking_thread()
     {
         Lock lock(m,boost::defer_lock);
- lock.timed_lock(boost::posix_time::milliseconds(50));
+#ifdef BOOST_THREAD_TEST_CHRONO
+ lock.try_lock_for(milliseconds(50));
+#else
+ lock.timed_lock(milliseconds(50));
+#endif
 
         boost::lock_guard<boost::mutex> lk(done_mutex);
         locked=lock.owns_lock();
@@ -125,7 +150,7 @@
 
     void locking_thread_through_constructor()
     {
- Lock lock(m,boost::posix_time::milliseconds(50));
+ Lock lock(m,milliseconds(50));
 
         boost::lock_guard<boost::mutex> lk(done_mutex);
         locked=lock.owns_lock();
@@ -153,8 +178,13 @@
         {
             {
                 boost::mutex::scoped_lock lk(done_mutex);
- BOOST_CHECK(done_cond.timed_wait(lk,boost::posix_time::seconds(2),
+#ifdef BOOST_THREAD_TEST_CHRONO
+ BOOST_CHECK(done_cond.wait_for(lk,seconds(2),
+ boost::bind(&this_type::is_done,this)));
+#else
+ BOOST_CHECK(done_cond.timed_wait(lk,seconds(2),
                                                  boost::bind(&this_type::is_done,this)));
+#endif
                 BOOST_CHECK(!locked);
             }
             
@@ -197,10 +227,12 @@
 
         // Test the lock's constructors.
         {
- // Construct and initialize an xtime for a fast time out.
- boost::system_time xt = boost::get_system_time()+boost::posix_time::milliseconds(100);
 
+ // Construct and initialize an xtime for a fast time out.
+ system_time_point xt = now()+milliseconds(100);
+
             timed_lock_type lock(mutex, xt);
+
             BOOST_CHECK(lock ? true : false);
         }
         {
@@ -211,17 +243,20 @@
         BOOST_CHECK(lock ? true : false);
 
         // Construct and initialize an xtime for a fast time out.
- boost::system_time timeout = boost::get_system_time()+boost::posix_time::milliseconds(100);
-
+ system_time_point timeout = now()+milliseconds(100);
         // Test the lock and the mutex with condition variables.
         // No one is going to notify this condition variable. We expect to
         // time out.
+#ifdef BOOST_THREAD_TEST_CHRONO
+ BOOST_CHECK(!condition.wait_until(lock, timeout, fake_predicate));
+#else
         BOOST_CHECK(!condition.timed_wait(lock, timeout, fake_predicate));
+#endif
         BOOST_CHECK(lock ? true : false);
 
- boost::system_time now=boost::get_system_time();
- boost::posix_time::milliseconds const timeout_resolution(20);
- BOOST_CHECK((timeout-timeout_resolution)<now);
+ system_time_point now2=now();
+ milliseconds const timeout_resolution(50);
+ BOOST_CHECK((timeout-timeout_resolution)<now2);
 
         // Test the lock, unlock and timedlock methods.
         lock.unlock();
@@ -230,16 +265,27 @@
         BOOST_CHECK(lock ? true : false);
         lock.unlock();
         BOOST_CHECK(!lock);
- boost::system_time target = boost::get_system_time()+boost::posix_time::milliseconds(100);
+ system_time_point target = now()+milliseconds(100);
+#ifdef BOOST_THREAD_TEST_CHRONO
+ BOOST_CHECK(lock.try_lock_until(target));
+#else
         BOOST_CHECK(lock.timed_lock(target));
+#endif
         BOOST_CHECK(lock ? true : false);
         lock.unlock();
         BOOST_CHECK(!lock);
 
- BOOST_CHECK(mutex.timed_lock(boost::posix_time::milliseconds(100)));
+#ifdef BOOST_THREAD_TEST_CHRONO
+ BOOST_CHECK(mutex.try_lock_for(milliseconds(100)));
+ mutex.unlock();
+
+ BOOST_CHECK(lock.try_lock_for(milliseconds(100)));
+#else
+ BOOST_CHECK(mutex.timed_lock(milliseconds(100)));
         mutex.unlock();
 
- BOOST_CHECK(lock.timed_lock(boost::posix_time::milliseconds(100)));
+ BOOST_CHECK(lock.timed_lock(milliseconds(100)));
+#endif
         BOOST_CHECK(lock ? true : false);
         lock.unlock();
         BOOST_CHECK(!lock);

Modified: sandbox/chrono/libs/thread/test/test_shared_mutex_timed_locks.cpp
==============================================================================
--- sandbox/chrono/libs/thread/test/test_shared_mutex_timed_locks.cpp (original)
+++ sandbox/chrono/libs/thread/test/test_shared_mutex_timed_locks.cpp 2010-05-21 20:37:21 EDT (Fri, 21 May 2010)
@@ -15,6 +15,25 @@
         BOOST_CHECK_EQUAL(value,expected_value); \
     }
 
+#ifdef BOOST_THREAD_TEST_CHRONO
+ using namespace boost::chrono;
+ typedef system_clock::time_point system_time_point;
+ system_time_point now() {return system_clock::now();}
+ template <typename OSTREAM>
+ OSTREAM& operator<<(OSTREAM & os, system_time_point t) {
+ os << t.count();
+ return os;
+ }
+#else
+ using namespace boost::posix_time;
+ typedef boost::system_time system_time_point;
+ system_time_point now() {return boost::get_system_time();}
+ template <typename OSTREAM>
+ OSTREAM& operator<<(OSTREAM & os, system_time_point t) {
+ return os;
+ }
+#endif
+
 
 void test_timed_lock_shared_times_out_if_write_lock_held()
 {
@@ -27,21 +46,36 @@
     boost::thread::sleep(delay(1));
     CHECK_LOCKED_VALUE_EQUAL(unblocked_mutex,unblocked_count,1u);
 
- boost::system_time const start=boost::get_system_time();
- boost::system_time const timeout=start+boost::posix_time::milliseconds(500);
- boost::posix_time::milliseconds const timeout_resolution(50);
+ system_time_point const start=now();
+ system_time_point const timeout=start+milliseconds(500);
+ milliseconds const timeout_resolution(50);
+#ifdef BOOST_THREAD_TEST_CHRONO
+ bool timed_lock_succeeded=rw_mutex.try_lock_shared_until(timeout);
+#else
     bool timed_lock_succeeded=rw_mutex.timed_lock_shared(timeout);
- BOOST_CHECK((timeout-timeout_resolution)<boost::get_system_time());
+#endif
+ system_time_point const end=now();
+ std::cout
+ << "timeout = " << timeout
+ << "end = " << end
+ << "\n";
+ std::cout.flush();
+ BOOST_CHECK((timeout-timeout_resolution)<end);
     BOOST_CHECK(!timed_lock_succeeded);
     if(timed_lock_succeeded)
     {
         rw_mutex.unlock_shared();
     }
 
- boost::posix_time::milliseconds const wait_duration(500);
- boost::system_time const timeout2=boost::get_system_time()+wait_duration;
+ milliseconds const wait_duration(500);
+ system_time_point const timeout2=now()+wait_duration;
+#ifdef BOOST_THREAD_TEST_CHRONO
+ timed_lock_succeeded=rw_mutex.try_lock_shared_for(wait_duration);
+#else
     timed_lock_succeeded=rw_mutex.timed_lock_shared(wait_duration);
- BOOST_CHECK((timeout2-timeout_resolution)<boost::get_system_time());
+#endif
+ BOOST_CHECK((timeout2-timeout_resolution)<now());
+
     BOOST_CHECK(!timed_lock_succeeded);
     if(timed_lock_succeeded)
     {
@@ -58,21 +92,29 @@
     boost::mutex finish_mutex;
     boost::mutex unblocked_mutex;
 
- boost::system_time const start=boost::get_system_time();
- boost::system_time const timeout=start+boost::posix_time::milliseconds(500);
- boost::posix_time::milliseconds const timeout_resolution(50);
+ system_time_point const start=now();
+ system_time_point const timeout=start+milliseconds(500);
+ milliseconds const timeout_resolution(50);
+#ifdef BOOST_THREAD_TEST_CHRONO
+ bool timed_lock_succeeded=rw_mutex.try_lock_shared_until(timeout);
+#else
     bool timed_lock_succeeded=rw_mutex.timed_lock_shared(timeout);
- BOOST_CHECK(boost::get_system_time()<timeout);
+#endif
+ BOOST_CHECK(now()<timeout);
     BOOST_CHECK(timed_lock_succeeded);
     if(timed_lock_succeeded)
     {
         rw_mutex.unlock_shared();
     }
 
- boost::posix_time::milliseconds const wait_duration(500);
- boost::system_time const timeout2=boost::get_system_time()+wait_duration;
+ milliseconds const wait_duration(500);
+ system_time_point const timeout2=now()+wait_duration;
+#ifdef BOOST_THREAD_TEST_CHRONO
+ timed_lock_succeeded=rw_mutex.try_lock_shared_for(wait_duration);
+#else
     timed_lock_succeeded=rw_mutex.timed_lock_shared(wait_duration);
- BOOST_CHECK(boost::get_system_time()<timeout2);
+#endif
+ BOOST_CHECK(now()<timeout2);
     BOOST_CHECK(timed_lock_succeeded);
     if(timed_lock_succeeded)
     {
@@ -92,21 +134,29 @@
     boost::thread::sleep(delay(1));
     CHECK_LOCKED_VALUE_EQUAL(unblocked_mutex,unblocked_count,1u);
 
- boost::system_time const start=boost::get_system_time();
- boost::system_time const timeout=start+boost::posix_time::milliseconds(500);
- boost::posix_time::milliseconds const timeout_resolution(50);
+ system_time_point const start=now();
+ system_time_point const timeout=start+milliseconds(500);
+ milliseconds const timeout_resolution(50);
+#ifdef BOOST_THREAD_TEST_CHRONO
+ bool timed_lock_succeeded=rw_mutex.try_lock_shared_until(timeout);
+#else
     bool timed_lock_succeeded=rw_mutex.timed_lock_shared(timeout);
- BOOST_CHECK(boost::get_system_time()<timeout);
+#endif
+ BOOST_CHECK(now()<timeout);
     BOOST_CHECK(timed_lock_succeeded);
     if(timed_lock_succeeded)
     {
         rw_mutex.unlock_shared();
     }
 
- boost::posix_time::milliseconds const wait_duration(500);
- boost::system_time const timeout2=boost::get_system_time()+wait_duration;
+ milliseconds const wait_duration(500);
+ system_time_point const timeout2=now()+wait_duration;
+#ifdef BOOST_THREAD_TEST_CHRONO
+ timed_lock_succeeded=rw_mutex.try_lock_shared_for(wait_duration);
+#else
     timed_lock_succeeded=rw_mutex.timed_lock_shared(wait_duration);
- BOOST_CHECK(boost::get_system_time()<timeout2);
+#endif
+ BOOST_CHECK(now()<timeout2);
     BOOST_CHECK(timed_lock_succeeded);
     if(timed_lock_succeeded)
     {
@@ -128,21 +178,35 @@
     boost::thread::sleep(delay(1));
     CHECK_LOCKED_VALUE_EQUAL(unblocked_mutex,unblocked_count,1u);
 
- boost::system_time const start=boost::get_system_time();
- boost::system_time const timeout=start+boost::posix_time::milliseconds(500);
- boost::posix_time::milliseconds const timeout_resolution(50);
+ system_time_point const start=now();
+ system_time_point const timeout=start+milliseconds(500);
+ milliseconds const timeout_resolution(50);
+#ifdef BOOST_THREAD_TEST_CHRONO
+ bool timed_lock_succeeded=rw_mutex.try_lock_until(timeout);
+#else
     bool timed_lock_succeeded=rw_mutex.timed_lock(timeout);
- BOOST_CHECK((timeout-timeout_resolution)<boost::get_system_time());
+#endif
+ system_time_point const end=now();
+ std::cout
+ << "timeout = " << timeout
+ << "end = " << end
+ << "\n";
+ std::cout.flush();
+ BOOST_CHECK((timeout-timeout_resolution)<end);
     BOOST_CHECK(!timed_lock_succeeded);
     if(timed_lock_succeeded)
     {
         rw_mutex.unlock();
     }
 
- boost::posix_time::milliseconds const wait_duration(500);
- boost::system_time const timeout2=boost::get_system_time()+wait_duration;
+ milliseconds const wait_duration(500);
+ system_time_point const timeout2=now()+wait_duration;
+#ifdef BOOST_THREAD_TEST_CHRONO
+ timed_lock_succeeded=rw_mutex.try_lock_for(wait_duration);
+#else
     timed_lock_succeeded=rw_mutex.timed_lock(wait_duration);
- BOOST_CHECK((timeout2-timeout_resolution)<boost::get_system_time());
+#endif
+ BOOST_CHECK((timeout2-timeout_resolution)<now());
     BOOST_CHECK(!timed_lock_succeeded);
     if(timed_lock_succeeded)
     {
@@ -159,21 +223,29 @@
     boost::mutex finish_mutex;
     boost::mutex unblocked_mutex;
 
- boost::system_time const start=boost::get_system_time();
- boost::system_time const timeout=start+boost::posix_time::milliseconds(500);
- boost::posix_time::milliseconds const timeout_resolution(50);
+ system_time_point const start=now();
+ system_time_point const timeout=start+milliseconds(500);
+ milliseconds const timeout_resolution(50);
+#ifdef BOOST_THREAD_TEST_CHRONO
+ bool timed_lock_succeeded=rw_mutex.try_lock_until(timeout);
+#else
     bool timed_lock_succeeded=rw_mutex.timed_lock(timeout);
- BOOST_CHECK(boost::get_system_time()<timeout);
+#endif
+ BOOST_CHECK(now()<timeout);
     BOOST_CHECK(timed_lock_succeeded);
     if(timed_lock_succeeded)
     {
         rw_mutex.unlock();
     }
 
- boost::posix_time::milliseconds const wait_duration(500);
- boost::system_time const timeout2=boost::get_system_time()+wait_duration;
+ milliseconds const wait_duration(500);
+ system_time_point const timeout2=now()+wait_duration;
+#ifdef BOOST_THREAD_TEST_CHRONO
+ timed_lock_succeeded=rw_mutex.try_lock_for(wait_duration);
+#else
     timed_lock_succeeded=rw_mutex.timed_lock(wait_duration);
- BOOST_CHECK(boost::get_system_time()<timeout2);
+#endif
+ BOOST_CHECK(now()<timeout2);
     BOOST_CHECK(timed_lock_succeeded);
     if(timed_lock_succeeded)
     {
@@ -193,21 +265,35 @@
     boost::thread::sleep(delay(1));
     CHECK_LOCKED_VALUE_EQUAL(unblocked_mutex,unblocked_count,1u);
 
- boost::system_time const start=boost::get_system_time();
- boost::system_time const timeout=start+boost::posix_time::milliseconds(500);
- boost::posix_time::milliseconds const timeout_resolution(50);
+ system_time_point const start=now();
+ system_time_point const timeout=start+milliseconds(500);
+ milliseconds const timeout_resolution(50);
+#ifdef BOOST_THREAD_TEST_CHRONO
+ bool timed_lock_succeeded=rw_mutex.try_lock_until(timeout);
+#else
     bool timed_lock_succeeded=rw_mutex.timed_lock(timeout);
- BOOST_CHECK((timeout-timeout_resolution)<boost::get_system_time());
+#endif
+ system_time_point const end=now();
+ std::cout
+ << "timeout = " << timeout
+ << "end = " << end
+ << "\n";
+ std::cout.flush();
+ BOOST_CHECK((timeout-timeout_resolution)<end);
     BOOST_CHECK(!timed_lock_succeeded);
     if(timed_lock_succeeded)
     {
         rw_mutex.unlock();
     }
 
- boost::posix_time::milliseconds const wait_duration(500);
- boost::system_time const timeout2=boost::get_system_time()+wait_duration;
+ milliseconds const wait_duration(500);
+ system_time_point const timeout2=now()+wait_duration;
+#ifdef BOOST_THREAD_TEST_CHRONO
+ timed_lock_succeeded=rw_mutex.try_lock_for(wait_duration);
+#else
     timed_lock_succeeded=rw_mutex.timed_lock(wait_duration);
- BOOST_CHECK((timeout2-timeout_resolution)<boost::get_system_time());
+#endif
+ BOOST_CHECK((timeout2-timeout_resolution)<now());
     BOOST_CHECK(!timed_lock_succeeded);
     if(timed_lock_succeeded)
     {
@@ -226,20 +312,32 @@
     unsigned unblocked_count=0;
     boost::mutex::scoped_lock finish_lock(finish_mutex);
     boost::thread reader(simple_reading_thread(rw_mutex,finish_mutex,unblocked_mutex,unblocked_count));
- boost::this_thread::sleep(boost::posix_time::seconds(1));
+#ifdef BOOST_THREAD_TEST_CHRONO
+ boost::this_thread::sleep_for(seconds(1));
+#else
+ boost::this_thread::sleep(seconds(1));
+#endif
     CHECK_LOCKED_VALUE_EQUAL(unblocked_mutex,unblocked_count,1u);
 
- boost::system_time const start=boost::get_system_time();
- boost::system_time const timeout=start+boost::posix_time::milliseconds(500);
+ system_time_point const start=now();
+ system_time_point const timeout=start+milliseconds(500);
+#ifdef BOOST_THREAD_TEST_CHRONO
+ bool timed_lock_succeeded=rw_mutex.try_lock_until(timeout);
+#else
     bool timed_lock_succeeded=rw_mutex.timed_lock(timeout);
+#endif
     BOOST_CHECK(!timed_lock_succeeded);
     if(timed_lock_succeeded)
     {
         rw_mutex.unlock();
     }
     
- boost::posix_time::milliseconds const wait_duration(500);
+ milliseconds const wait_duration(500);
+#ifdef BOOST_THREAD_TEST_CHRONO
+ timed_lock_succeeded=rw_mutex.try_lock_shared_for(wait_duration);
+#else
     timed_lock_succeeded=rw_mutex.timed_lock_shared(wait_duration);
+#endif
     BOOST_CHECK(timed_lock_succeeded);
     if(timed_lock_succeeded)
     {

Modified: sandbox/chrono/libs/thread/test/test_thread.cpp
==============================================================================
--- sandbox/chrono/libs/thread/test/test_thread.cpp (original)
+++ sandbox/chrono/libs/thread/test/test_thread.cpp 2010-05-21 20:37:21 EDT (Fri, 21 May 2010)
@@ -41,10 +41,20 @@
 {
     boost::xtime xt = delay(3);
     boost::thread::sleep(xt);
-
+
     // Ensure it's in a range instead of checking actual equality due to time
     // lapse
     BOOST_CHECK(in_range(xt, 2));
+
+}
+
+void test_sleep_chrono()
+{
+ boost::this_thread::sleep_for(boost::chrono::seconds(3));
+
+ // Ensure it's in a range instead of checking actual equality due to time
+ // lapse
+ //~ TBDONE BOOST_CHECK(in_range(xt, 2));
 }
 
 void do_test_creation()
@@ -222,6 +232,7 @@
         BOOST_TEST_SUITE("Boost.Threads: thread test suite");
 
     test->add(BOOST_TEST_CASE(test_sleep));
+ test->add(BOOST_TEST_CASE(test_sleep_chrono));
     test->add(BOOST_TEST_CASE(test_creation));
     test->add(BOOST_TEST_CASE(test_id_comparison));
     test->add(BOOST_TEST_CASE(test_thread_interrupts_at_interruption_point));


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