[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
Tue Mar 23 09:13:34 PDT 2021


mstorsjo updated this revision to Diff 332693.
mstorsjo added a comment.

Expanded the loops to check for now >= end and breaking, before calling wait_for again.


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::time_point now;
+    do {
+        now = Clock::now();
+        if (now >= wait_end) break;
+    } while (test2 == 0 && cv.wait_for(lk, wait_end - now) == 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::time_point now;
+    do {
+        now = Clock::now();
+        if (now >= wait_end) break;
+    } while (test2 == 0 && cv.wait_for(lk, wait_end - now) == std::cv_status::no_timeout);
     Clock::time_point t1 = Clock::now();
     if (runs == 0)
     {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99175.332693.patch
Type: text/x-patch
Size: 1747 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210323/df23a213/attachment.bin>


More information about the libcxx-commits mailing list