From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25368 invoked by alias); 10 Jul 2018 10:09:49 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 25265 invoked by uid 89); 10 Jul 2018 10:09:48 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.2 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_INFOUSMEBIZ,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 spammy=H*RU:202, Hx-spam-relays-external:202 X-HELO: NAM05-DM3-obe.outbound.protection.outlook.com Received: from mail-eopbgr730093.outbound.protection.outlook.com (HELO NAM05-DM3-obe.outbound.protection.outlook.com) (40.107.73.93) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 10 Jul 2018 10:09:46 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brightsigninfo.onmicrosoft.com; s=selector1-brightsign-biz; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=M85+YDYV4CSnC33kivXrS7ZXOVtr8fI14QBR15XUwRU=; b=oQX5AWjsw47U50vCk4cT0rS3hvmCK6Ic4TRrstqSL/YgCWkIO/VP9OnzTro4MQOmTJwaHsQqqDVQLc5fyPetd+M+C6DOM4l6VHWGc+qIZsBFf301g21fjHF7hqG34nE2LpPENxPCOv0cmqOTQDjf87f615rALqkRJgtL4srGRkw= Received: from DM3PR08CA0008.namprd08.prod.outlook.com (2603:10b6:0:52::18) by BYAPR08MB3910.namprd08.prod.outlook.com (2603:10b6:a02:84::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.930.21; Tue, 10 Jul 2018 10:09:42 +0000 Received: from BN3NAM04FT043.eop-NAM04.prod.protection.outlook.com (2a01:111:f400:7e4e::202) by DM3PR08CA0008.outlook.office365.com (2603:10b6:0:52::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.930.19 via Frontend Transport; Tue, 10 Jul 2018 10:09:41 +0000 Authentication-Results: spf=pass (sender IP is 213.210.30.29) smtp.mailfrom=brightsign.biz; gcc.gnu.org; dkim=none (message not signed) header.d=none;gcc.gnu.org; dmarc=none action=none header.from=mcrowe.com; Received-SPF: Pass (protection.outlook.com: domain of brightsign.biz designates 213.210.30.29 as permitted sender) receiver=protection.outlook.com; client-ip=213.210.30.29; helo=elite.brightsign; Received: from elite.brightsign (213.210.30.29) by BN3NAM04FT043.mail.protection.outlook.com (10.152.93.79) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.930.16 via Frontend Transport; Tue, 10 Jul 2018 10:09:41 +0000 Received: from chuckie.brightsign ([fd44:d8b8:cab5:cb01::19] helo=chuckie) by elite.brightsign with esmtp (Exim 4.89) (envelope-from ) id 1fcpaW-0000f9-GK; Tue, 10 Jul 2018 11:09:40 +0100 Received: from mac by chuckie with local (Exim 4.89) (envelope-from ) id 1fcpaW-0001YC-D3; Tue, 10 Jul 2018 11:09:40 +0100 From: Mike Crowe To: , CC: Mike Crowe Subject: [PATCH 2/2] condition_variable: Use steady_clock to implement wait_for Date: Tue, 10 Jul 2018 10:09:00 -0000 Message-ID: <20180710100929.32704-2-mac@mcrowe.com> In-Reply-To: <20180710100929.32704-1-mac@mcrowe.com> References: <20180710100929.32704-1-mac@mcrowe.com> Return-Path: mcrowe@brightsign.biz MIME-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: quoted-printable X-SW-Source: 2018-07/txt/msg00477.txt.bz2 I believe[1][2] that the C++ standard says that std::condition_variable::wait_for should be implemented to be equivalent to: return wait_until(lock, chrono::steady_clock::now() + rel_time); But the existing implementation uses chrono::system_clock. Now that wait_until has potentially-different behaviour for chrono::steady_clock, let's at least try to wait using the correct clock. [1] https://en.cppreference.com/w/cpp/thread/condition_variable/wait_for [2] https://github.com/cplusplus/draft/blob/master/source/threads.tex --- libstdc++-v3/ChangeLog | 3 +++ libstdc++-v3/include/std/condition_variable | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index ea7875ace9f..4500273ace7 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,4 +1,7 @@ 2018-07-09 Mike Crowe + * include/std/condition_variable (wait_for): Use steady_clock. + +2018-07-09 Mike Crowe * include/std/condition_variable (wait_until): Only report timeout if we really have timed out when measured against the caller-supplied clock. diff --git a/libstdc++-v3/include/std/condition_variable b/libstdc++-v3/inc= lude/std/condition_variable index a2d146a9b09..ce583990b9d 100644 --- a/libstdc++-v3/include/std/condition_variable +++ b/libstdc++-v3/include/std/condition_variable @@ -65,6 +65,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION class condition_variable { typedef chrono::system_clock __clock_t; + typedef chrono::steady_clock __steady_clock_t; typedef __gthread_cond_t __native_type; #ifdef __GTHREAD_COND_INIT @@ -142,11 +143,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION wait_for(unique_lock& __lock, const chrono::duration<_Rep, _Period>& __rtime) { - using __dur =3D typename __clock_t::duration; + using __dur =3D typename __steady_clock_t::duration; auto __reltime =3D chrono::duration_cast<__dur>(__rtime); if (__reltime < __rtime) ++__reltime; - return wait_until(__lock, __clock_t::now() + __reltime); + return wait_until(__lock, __steady_clock_t::now() + __reltime); } template -- 2.11.0 BrightSign considers your privacy to be very important. The emails you send= to us will be protected and secured. Furthermore, we will only use your em= ail and contact information for the reasons you sent them to us and for tra= cking how effectively we respond to your requests.