From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 38251 invoked by alias); 29 Nov 2018 10:18:28 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 37553 invoked by uid 89); 29 Nov 2018 10:18:28 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-100.9 required=5.0 tests=BAYES_00,GOOD_FROM_CORINNA_CYGWIN,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 spammy=developer, iii, H*Ad:D*apache.org, uploaded X-HELO: mout.kundenserver.de Received: from mout.kundenserver.de (HELO mout.kundenserver.de) (217.72.192.73) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 29 Nov 2018 10:18:26 +0000 Received: from calimero.vinschen.de ([24.134.7.25]) by mrelayeu.kundenserver.de (mreue107 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MrPRB-1fdncg45W3-00oYiW; Thu, 29 Nov 2018 11:18:22 +0100 Received: by calimero.vinschen.de (Postfix, from userid 500) id 704E7A8058A; Thu, 29 Nov 2018 11:18:21 +0100 (CET) Date: Thu, 29 Nov 2018 10:18:00 -0000 From: Corinna Vinschen To: cygwin@cygwin.com Cc: "James E. King III" Subject: Re: pthread_cond_timedwait with setclock(CLOCK_MONOTONIC) times out early Message-ID: <20181129101821.GZ30649@calimero.vinschen.de> Reply-To: cygwin@cygwin.com Mail-Followup-To: cygwin@cygwin.com, "James E. King III" References: <20181126153545.GM30649@calimero.vinschen.de> <20181126164657.GN30649@calimero.vinschen.de> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="aiCxlS1GuupXjEh3" Content-Disposition: inline In-Reply-To: <20181126164657.GN30649@calimero.vinschen.de> User-Agent: Mutt/1.9.2 (2017-12-15) X-SW-Source: 2018-11/txt/msg00238.txt.bz2 --aiCxlS1GuupXjEh3 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-length: 2493 On Nov 26 17:46, Corinna Vinschen wrote: > On Nov 26 10:47, James E. King III wrote: > > On Mon, Nov 26, 2018 at 10:35 AM Corinna Vinschen > > wrote: > > > > > > On Nov 25 09:01, James E. King III wrote: > > > > I have isolated a problem in pthread_cond_timedwait when the condat= tr > > > > is used to set the clock type to CLOCK_MONOTONIC. In this case even > > > > though a target time point in the future is specified, the call > > > > returns ETIMEDOUT but a subsequent call to > > > > clock_gettime(CLOCK_MONOTONIC) shows the desired time point was not > > > > reached. > > > > > > > > $ gcc timed_wait_short.c -o timed_wait_short > > > > $ ./timed_wait_short.exe > > > > [...] > > > > begin: 521056s 671907500n > > > > target: 521056s 721907500n > > > > end: 521056s 721578000n > > > > ok: false > > > > > > > > I have attached the source code. > > > > > > Thanks for the testcase. The problem is this: > > > [...] > > > At the moment I only have an *ugly* idea: We can always add the > > > coarsest resolution of the wait functions (typically 15.625 ms) to the > > > relative timeout value computed from the absolute timeout given to > > > pthread_cond_timedwait. In my testing this is sufficient since the > > > difference between target and actual end time is always < 15ms, in > > > thousands of runs. > > > > > > Thoughts? > > > > > > > > > Thanks, > > > Corinna > > > > > > (*) https://docs.microsoft.com/en-us/windows/desktop/Sync/wait-functi= ons#wait-functions-and-time-out-intervals > > > > > > -- > > > Corinna Vinschen > > > Cygwin Maintainer > >=20 > > Some thoughts: > >=20 > > https://cygwin.com/git/gitweb.cgi?p=3Dnewlib-cygwin.git;a=3Dblob;f=3Dwi= nsup/cygwin/thread.cc;h=3D0bddaf345d255ae39187458dc6d02b1b4c8087c1;hb=3DHEA= D#l2546 > >=20 > > In pthread_convert_abstime, line 2564, care is taken to adjust for > > rounding errors. > > At line 2574, the rounding is not accounted for when adjusting for a > > relative wait because it is a monotonic clock. > > Wouldn't that rounding error cause it to wait less time? >=20 > Au contraire: >=20 > - The end time you're waiting for is rounded *up*. > - The current time is rounded *down* > - So end time - current time is always bigger than required > on the 100ns level. >=20 > Make sense? I created a patch and uploaded new developer snapshots to https://cygwin.com/snapshots/ Please give them a try. Thanks, Corinna --=20 Corinna Vinschen Cygwin Maintainer --aiCxlS1GuupXjEh3 Content-Type: application/pgp-signature; name="signature.asc" Content-length: 833 -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEoVYPmneWZnwT6kwF9TYGna5ET6AFAlv/vO0ACgkQ9TYGna5E T6C4fQ//TZWre9beoFyGpRuXfDl0SaEPNYFr0Nypa1ltSTQtjBbuOSISX/XOzQhQ 5O1QslCB8H7iXBUThYV5wYVZkUtUducylP5+41yeeBNq0goMeT+THnRMtahUiHG4 RU4NPRXlQJLp/yldIeMfzOudIiSUo+ceeFhsykrsw/gfx/K7/+7IFQdyg+QrYTT8 pT3o6gYGYdUBJ8oJGBM04OMrezr4ljbIXXDQYrMH1L6M0bp4nCE2OTMDuLQBViec xjzmB3y1byBfi8t+nQdBiMkNfA0DiWCP1dGmPGQHZae8knWoP1j4X4Cvxy5xSJDa BgYI3gPohki8p+4q/JdtUH52ZVKDtZRQxWcDnTIbawGVaLVz8X7o6FsDsAUujQtn u0xbh2/ZUMcqrizpoJvskfS4LVjVPH9BohtBC7Crp74rpSPXZNqhIeXr+uZv3H+o /yY3KHaDylDgREKQWffE+EA5Lm3IrXmTYzLfioJKMcB89pQNuXGga1g6a0kcecwT nTdMCCWPg6dsehlh+76FXvXV5tfmAhuLRfQSHCs9t3CWAOAF7vdBdU+opGi9Ghvj zi3+wcR6G9WEfmpM98U4FoX1nIOnugq33rM0naRoE3QXfKP6o6Gku/5PNXnX4kS1 PMED2TcAaxzw6DEpu9+Iwagp2e8fE7Q6mGsHuTxDOQF1mxD9iG0= =+gio -----END PGP SIGNATURE----- --aiCxlS1GuupXjEh3--