From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 62B2739874BF; Fri, 11 Sep 2020 13:29:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 62B2739874BF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1599830952; bh=XXSsa76+uIn0BJDdA9I09PrFN2QuRNRgu1Jdjotfhq0=; h=From:To:Subject:Date:From; b=QczNvvPoQluJtOI+etGe8Y4ZAhhOkwZ5w/+qvs0+02w4+GGSwgDsY6x8r6wLgt+e0 tNftpA9cnvp08udvLzaXT1fxDAdycg+aqWoOHzs7M8TNvQwg+KCUz7RTmxXjajDKlS 0D1/9/CcXaprEAPvMT60csqim2kWC5DkObO5BKbM= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r11-3152] libstdc++: Improve std::async test X-Act-Checkin: gcc X-Git-Author: Mike Crowe X-Git-Refname: refs/heads/master X-Git-Oldrev: 55bdee9af3cff04192c64a573fa1767b48918efa X-Git-Newrev: f639343dc8c4fa65342a8c1fd43384999cf9f9d0 Message-Id: <20200911132912.62B2739874BF@sourceware.org> Date: Fri, 11 Sep 2020 13:29:12 +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: Fri, 11 Sep 2020 13:29:12 -0000 https://gcc.gnu.org/g:f639343dc8c4fa65342a8c1fd43384999cf9f9d0 commit r11-3152-gf639343dc8c4fa65342a8c1fd43384999cf9f9d0 Author: Mike Crowe Date: Fri Sep 11 14:24:59 2020 +0100 libstdc++: Improve std::async test Add tests for waiting for the future using both chrono::steady_clock and chrono::system_clock in preparation for dealing with those clocks properly in futex.cc. libstdc++-v3/ChangeLog: * testsuite/30_threads/async/async.cc (test02): Test steady_clock with std::future::wait_until. (test03): Add new test templated on clock type waiting for future associated with async to resolve. (main): Call test03 to test both system_clock and steady_clock. Diff: --- libstdc++-v3/testsuite/30_threads/async/async.cc | 33 ++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/libstdc++-v3/testsuite/30_threads/async/async.cc b/libstdc++-v3/testsuite/30_threads/async/async.cc index 8c3a0c18768..2089b1c45ef 100644 --- a/libstdc++-v3/testsuite/30_threads/async/async.cc +++ b/libstdc++-v3/testsuite/30_threads/async/async.cc @@ -50,17 +50,50 @@ void test02() VERIFY( status == std::future_status::timeout ); status = f1.wait_until(std::chrono::system_clock::now()); VERIFY( status == std::future_status::timeout ); + status = f1.wait_until(std::chrono::steady_clock::now()); + VERIFY( status == std::future_status::timeout ); l.unlock(); // allow async thread to proceed f1.wait(); // wait for it to finish status = f1.wait_for(std::chrono::milliseconds(0)); VERIFY( status == std::future_status::ready ); status = f1.wait_until(std::chrono::system_clock::now()); VERIFY( status == std::future_status::ready ); + status = f1.wait_until(std::chrono::steady_clock::now()); + VERIFY( status == std::future_status::ready ); +} + +// This test is prone to failures if run on a loaded machine where the +// kernel decides not to schedule us for several seconds. It also +// assumes that no-one will warp CLOCK whilst the test is +// running when CLOCK is std::chrono::system_clock. +template +void test03() +{ + auto const start = CLOCK::now(); + future f1 = async(launch::async, []() { + std::this_thread::sleep_for(std::chrono::seconds(2)); + }); + std::future_status status; + + status = f1.wait_for(std::chrono::milliseconds(500)); + VERIFY( status == std::future_status::timeout ); + + status = f1.wait_until(start + std::chrono::seconds(1)); + VERIFY( status == std::future_status::timeout ); + + status = f1.wait_until(start + std::chrono::seconds(5)); + VERIFY( status == std::future_status::ready ); + + auto const elapsed = CLOCK::now() - start; + VERIFY( elapsed >= std::chrono::seconds(2) ); + VERIFY( elapsed < std::chrono::seconds(5) ); } int main() { test01(); test02(); + test03(); + test03(); return 0; }