From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2140) id 8EE553858002; Wed, 24 Mar 2021 09:15:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8EE553858002 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Alexandre Oliva To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc(refs/users/aoliva/heads/testme)] improve future::poll calibration loop X-Act-Checkin: gcc X-Git-Author: Alexandre Oliva X-Git-Refname: refs/users/aoliva/heads/testme X-Git-Oldrev: e6664089e87347903196b695c2aceb8972db0ff8 X-Git-Newrev: 302e9dc278d05495655a4e342fea8349236508ae Message-Id: <20210324091518.8EE553858002@sourceware.org> Date: Wed, 24 Mar 2021 09:15:18 +0000 (GMT) X-BeenThere: libstdc++-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Mar 2021 09:15:18 -0000 https://gcc.gnu.org/g:302e9dc278d05495655a4e342fea8349236508ae commit 302e9dc278d05495655a4e342fea8349236508ae Author: Alexandre Oliva Date: Wed Mar 24 05:44:41 2021 -0300 improve future::poll calibration loop 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. Diff: --- libstdc++-v3/testsuite/30_threads/future/members/poll.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/testsuite/30_threads/future/members/poll.cc b/libstdc++-v3/testsuite/30_threads/future/members/poll.cc index 133dae15ac4..4c846d0b7ba 100644 --- a/libstdc++-v3/testsuite/30_threads/future/members/poll.cc +++ b/libstdc++-v3/testsuite/30_threads/future/members/poll.cc @@ -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 pc; + future 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++; }