]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
improve future::poll calibration loop
authorAlexandre Oliva <oliva@adacore.com>
Wed, 31 Mar 2021 18:34:47 +0000 (15:34 -0300)
committerAlexandre Oliva <oliva@gnu.org>
Wed, 31 Mar 2021 18:45:56 +0000 (15:45 -0300)
The calibration loop I've recently added to the libstdc++
future/members/poll.cc tests could still select iteration counts that
might yield zero-time measurements for the wait_for when ready loop.

Waiting for a future that has already had a value set is presumably
uniformly faster than a zero-timed wait for a result, so I've changed
the calibration loop to use the former.

We might still be unlucky and get nonzero from the initial loop, so
that the calibration is skipped altogether, but then get zero from the
later when-ready loop.  I'm not dealing with this case in this patch.

for  libstdc++-v3/ChangeLog

* testsuite/30_threads/future/members/poll.cc: Use faster
after-ready call in the calibration loop.

libstdc++-v3/testsuite/30_threads/future/members/poll.cc

index 133dae15ac47140c1321d77a9dc8eb0cc8065ee8..4c846d0b7baf5cec7b51f3c35501637488254a8c 100644 (file)
@@ -55,6 +55,12 @@ int main()
      Attempt to calibrate it.  */
   if (start == stop)
     {
+      /* After set_value, wait_for is faster, so use that for the
+        calibration to avoid zero at low clock resultions.  */
+      promise<int> pc;
+      future<int> fc = pc.get_future();
+      pc.set_value(1);
+
       /* Loop until the clock advances, so that start is right after a
         time increment.  */
       do
@@ -65,7 +71,7 @@ int main()
         after another time increment.  */
       do
        {
-         f.wait_for(chrono::seconds(0));
+         fc.wait_for(chrono::seconds(0));
          stop = chrono::high_resolution_clock::now();
          i++;
        }