]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/boost/libs/thread/test/sync/conditions/condition_variable/wait_for_pred_pass.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / thread / test / sync / conditions / condition_variable / wait_for_pred_pass.cpp
index bfe12cf1ad037710c6ac4a400bbcf8b5e8d82c5b..7a3093606a0d86dbaa7010c84461f0a2466e0eab 100644 (file)
@@ -21,6 +21,8 @@
 #include <boost/thread/mutex.hpp>
 #include <boost/thread/thread.hpp>
 #include <boost/detail/lightweight_test.hpp>
+#include <cassert>
+#include <iostream>
 
 #if defined BOOST_THREAD_USES_CHRONO
 
@@ -49,34 +51,40 @@ int runs = 0;
 
 void f()
 {
-  typedef boost::chrono::system_clock Clock;
-  typedef boost::chrono::milliseconds milliseconds;
-  boost::unique_lock < boost::mutex > lk(mut);
-  BOOST_TEST(test2 == 0);
-  test1 = 1;
-  cv.notify_one();
-  Clock::time_point t0 = Clock::now();
-  int count=0;
-  //bool r =
-      (void)cv.wait_for(lk, milliseconds(250), Pred(test2));
-  count++;
-  Clock::time_point t1 = Clock::now();
-  if (runs == 0)
-  {
-    // This test is spurious as it depends on the time the thread system switches the threads
-    BOOST_TEST(t1 - t0 < milliseconds(250+1000));
-    BOOST_TEST(test2 != 0);
-  }
-  else
-  {
-    BOOST_TEST(t1 - t0 - milliseconds(250) < milliseconds(count*250+2));
-    BOOST_TEST(test2 == 0);
+  try {
+    typedef boost::chrono::system_clock Clock;
+    typedef boost::chrono::milliseconds milliseconds;
+    boost::unique_lock < boost::mutex > lk(mut);
+    assert(test2 == 0);
+    test1 = 1;
+    cv.notify_one();
+    Clock::time_point t0 = Clock::now();
+    int count=0;
+    //bool r =
+        (void)cv.wait_for(lk, milliseconds(250), Pred(test2));
+    count++;
+    Clock::time_point t1 = Clock::now();
+    if (runs == 0)
+    {
+      // This test is spurious as it depends on the time the thread system switches the threads
+      assert(t1 - t0 < milliseconds(250+1000));
+      assert(test2 != 0);
+    }
+    else
+    {
+      assert(t1 - t0 - milliseconds(250) < milliseconds(count*250+2));
+      assert(test2 == 0);
+    }
+    ++runs;
+  } catch(...) {
+    std::cout << "ERROR exception" << __LINE__ << std::endl;
+    assert(false);
   }
-  ++runs;
 }
 
 int main()
 {
+  try
   {
     boost::unique_lock < boost::mutex > lk(mut);
     boost::thread t(f);
@@ -88,9 +96,13 @@ int main()
     lk.unlock();
     cv.notify_one();
     t.join();
+  } catch(...) {
+    BOOST_TEST(false);
+    std::cout << "ERROR exception" << __LINE__ << std::endl;
   }
   test1 = 0;
   test2 = 0;
+  try
   {
     boost::unique_lock < boost::mutex > lk(mut);
     boost::thread t(f);
@@ -100,6 +112,9 @@ int main()
     BOOST_TEST(test1 != 0);
     lk.unlock();
     t.join();
+  } catch(...) {
+    BOOST_TEST(false);
+    std::cout << "ERROR exception" << __LINE__ << std::endl;
   }
 
   return boost::report_errors();