Imported Upstream version 1.57.0
[platform/upstream/boost.git] / libs / thread / test / threads / this_thread / sleep_until / sleep_until_pass.cpp
index 4adcd3c..8f003d8 100644 (file)
@@ -15,7 +15,7 @@
 
 // thread::id this_thread::get_id();
 
-#include <boost/thread/thread.hpp>
+#include <boost/thread/thread_only.hpp>
 #include <cstdlib>
 #include <algorithm>
 
 
 int main()
 {
-  typedef boost::chrono::system_clock Clock;
-  typedef Clock::time_point time_point;
-  typedef Clock::duration duration;
-  boost::chrono::milliseconds ms(500);
-  time_point t0 = Clock::now();
-  boost::this_thread::sleep_until(t0 + ms);
-  time_point t1 = Clock::now();
-  boost::chrono::nanoseconds ns = (t1 - t0) - ms;
-  boost::chrono::nanoseconds err = ms / 100;
-  // The time slept is within 1% of 500ms
-  // This test is spurious as it depends on the time the thread system switches the threads
-  BOOST_TEST((std::max)(ns.count(), -ns.count()) < (err+boost::chrono::milliseconds(1000)).count());
-  //BOOST_TEST(std::abs(static_cast<long>(ns.count())) < (err+boost::chrono::milliseconds(1000)).count());
+  {
+    typedef boost::chrono::steady_clock Clock;
+    typedef Clock::time_point time_point;
+    typedef Clock::duration duration;
+    boost::chrono::milliseconds ms(500);
+    time_point t0 = Clock::now();
+    boost::this_thread::sleep_until(t0 + ms);
+    time_point t1 = Clock::now();
+    boost::chrono::nanoseconds ns = (t1 - t0) - ms;
+    boost::chrono::nanoseconds err = ms / 100;
+    // The time slept is within 1% of 500ms
+    // This test is spurious as it depends on the time the thread system switches the threads
+    BOOST_TEST((std::max)(ns.count(), -ns.count()) < (err+boost::chrono::milliseconds(1000)).count());
+    //BOOST_TEST(std::abs(static_cast<long>(ns.count())) < (err+boost::chrono::milliseconds(1000)).count());
+  }
+  {
+    typedef boost::chrono::system_clock Clock;
+    typedef Clock::time_point time_point;
+    typedef Clock::duration duration;
+    boost::chrono::milliseconds ms(500);
+    time_point t0 = Clock::now();
+    boost::this_thread::sleep_until(t0 + ms);
+    time_point t1 = Clock::now();
+    boost::chrono::nanoseconds ns = (t1 - t0) - ms;
+    boost::chrono::nanoseconds err = ms / 100;
+    // The time slept is within 1% of 500ms
+    // This test is spurious as it depends on the time the thread system switches the threads
+    BOOST_TEST((std::max)(ns.count(), -ns.count()) < (err+boost::chrono::milliseconds(1000)).count());
+    //BOOST_TEST(std::abs(static_cast<long>(ns.count())) < (err+boost::chrono::milliseconds(1000)).count());
+  }
+  {
+    typedef boost::chrono::steady_clock Clock;
+    typedef Clock::time_point time_point;
+    typedef Clock::duration duration;
+    boost::chrono::milliseconds ms(500);
+    time_point t0 = Clock::now();
+    boost::this_thread::no_interruption_point::sleep_until(t0 + ms);
+    time_point t1 = Clock::now();
+    boost::chrono::nanoseconds ns = (t1 - t0) - ms;
+    boost::chrono::nanoseconds err = ms / 100;
+    // The time slept is within 1% of 500ms
+    // This test is spurious as it depends on the time the thread system switches the threads
+    BOOST_TEST((std::max)(ns.count(), -ns.count()) < (err+boost::chrono::milliseconds(1000)).count());
+    //BOOST_TEST(std::abs(static_cast<long>(ns.count())) < (err+boost::chrono::milliseconds(1000)).count());
+  }
+  {
+    typedef boost::chrono::system_clock Clock;
+    typedef Clock::time_point time_point;
+    typedef Clock::duration duration;
+    boost::chrono::milliseconds ms(500);
+    time_point t0 = Clock::now();
+    boost::this_thread::no_interruption_point::sleep_until(t0 + ms);
+    time_point t1 = Clock::now();
+    boost::chrono::nanoseconds ns = (t1 - t0) - ms;
+    boost::chrono::nanoseconds err = ms / 100;
+    // The time slept is within 1% of 500ms
+    // This test is spurious as it depends on the time the thread system switches the threads
+    BOOST_TEST((std::max)(ns.count(), -ns.count()) < (err+boost::chrono::milliseconds(1000)).count());
+    //BOOST_TEST(std::abs(static_cast<long>(ns.count())) < (err+boost::chrono::milliseconds(1000)).count());
+  }
   return boost::report_errors();
 
 }