[libcxx-commits] [PATCH] D99175: [libcxx] [test] Make the condvar wait_for tests less brittle

Martin Storsjö via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu Apr 1 11:45:34 PDT 2021


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG01aa9e1f6e7d: [libcxx] [test] Make the condvar wait_for tests less brittle (authored by mstorsjo).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99175/new/

https://reviews.llvm.org/D99175

Files:
  libcxx/test/std/thread/thread.condition/thread.condition.condvar/wait_for.pass.cpp
  libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_for.pass.cpp


Index: libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_for.pass.cpp
===================================================================
--- libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_for.pass.cpp
+++ libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_for.pass.cpp
@@ -47,9 +47,12 @@
     test1 = 1;
     cv.notify_one();
     Clock::time_point t0 = Clock::now();
-    while (test2 == 0 &&
-           cv.wait_for(lk, milliseconds(250)) == std::cv_status::no_timeout)
-        ;
+    Clock::time_point wait_end = t0 + milliseconds(250);
+    Clock::duration d;
+    do {
+        d = wait_end - Clock::now();
+        if (d <= milliseconds(0)) break;
+    } while (test2 == 0 && cv.wait_for(lk, d) == std::cv_status::no_timeout);
     Clock::time_point t1 = Clock::now();
     if (runs == 0)
     {
Index: libcxx/test/std/thread/thread.condition/thread.condition.condvar/wait_for.pass.cpp
===================================================================
--- libcxx/test/std/thread/thread.condition/thread.condition.condvar/wait_for.pass.cpp
+++ libcxx/test/std/thread/thread.condition/thread.condition.condvar/wait_for.pass.cpp
@@ -44,9 +44,12 @@
     test1 = 1;
     cv.notify_one();
     Clock::time_point t0 = Clock::now();
-    while (test2 == 0 &&
-           cv.wait_for(lk, milliseconds(250)) == std::cv_status::no_timeout)
-        ;
+    Clock::time_point wait_end = t0 + milliseconds(250);
+    Clock::duration d;
+    do {
+        d = wait_end - Clock::now();
+        if (d <= milliseconds(0)) break;
+    } while (test2 == 0 && cv.wait_for(lk, d) == std::cv_status::no_timeout);
     Clock::time_point t1 = Clock::now();
     if (runs == 0)
     {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99175.334789.patch
Type: text/x-patch
Size: 1741 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210401/5500b485/attachment.bin>


More information about the libcxx-commits mailing list