From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26907 invoked by alias); 26 Nov 2018 16:47:03 -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 26894 invoked by uid 89); 26 Nov 2018 16:47:02 -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= X-HELO: mout.kundenserver.de Received: from mout.kundenserver.de (HELO mout.kundenserver.de) (212.227.126.133) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 26 Nov 2018 16:47:01 +0000 Received: from calimero.vinschen.de ([24.134.7.25]) by mrelayeu.kundenserver.de (mreue009 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MhlCa-1fnsYM2WH2-00dkch for ; Mon, 26 Nov 2018 17:46:58 +0100 Received: by calimero.vinschen.de (Postfix, from userid 500) id AB0E3A8058A; Mon, 26 Nov 2018 17:46:57 +0100 (CET) Date: Mon, 26 Nov 2018 16:47:00 -0000 From: Corinna Vinschen To: cygwin@cygwin.com Subject: Re: pthread_cond_timedwait with setclock(CLOCK_MONOTONIC) times out early Message-ID: <20181126164657.GN30649@calimero.vinschen.de> Reply-To: cygwin@cygwin.com Mail-Followup-To: cygwin@cygwin.com References: <20181126153545.GM30649@calimero.vinschen.de> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="Il7n/DHsA0sMLmDu" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.2 (2017-12-15) X-SW-Source: 2018-11/txt/msg00189.txt.bz2 --Il7n/DHsA0sMLmDu Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-length: 2200 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 condattr > > > 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-function= s#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=3Dwins= up/cygwin/thread.cc;h=3D0bddaf345d255ae39187458dc6d02b1b4c8087c1;hb=3DHEAD#= 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? Au contraire: - 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. Make sense? Corinna --=20 Corinna Vinschen Cygwin Maintainer --Il7n/DHsA0sMLmDu Content-Type: application/pgp-signature; name="signature.asc" Content-length: 833 -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEoVYPmneWZnwT6kwF9TYGna5ET6AFAlv8I4EACgkQ9TYGna5E T6ALLQ//W/Xqu2ZW1cb78ST1/An2Let4agJ62IP3WTdmAF0d8bcsFwf5HW9HhBkE zHdYii47pXwKNjtSr4sybenBTmLNe7XmhX487GuQ7fpaB5Mlo2JhOomc3bPrDaSd N0kFXWtp0kIZTDbUQs6Oa1Zec3tHToEZnwcs9gvNxhZATIfNxMB6q6qFDIJm2SVo iflTSGI5XijATSwkMda2rkE+ShCHeLq1+7ryhOkg9YjFuACLYbMJOXnb3UBVyBAW pEmJdNoCTSAx371nbFr2AnZiUUoxXosXugI8kDy2KkRpp1HEjmppGjJJGr3IzvIO of8ZuxLzlWsa1PiPeCAAeteVagFz8vE38pzndbaKNtsyPX4RF3MrM5MXDcO9wSIl mTrm4zRGWqX54smVOpv/gHndvHcwSP/ybx1vMlSef1Y1BMwKKS6ftT7OykLxFfGM SEFWVyd4yIBJWSNdk3V3UYmZzuWZvaHavxjCQpvb2EN/YR4rDbH4rt+E90McQOe4 LHEo+DMOv6Gz80/AHhIHAH4RP6Ulyw5iKq7ealWJt/64tvwqQUGdEbvO4x4Sdgs1 ZX3rKHeXHgIQLVeT4dVNPldoFoe/g8uXkU9hTR4ZHM9F+S3cJW3vT4XeevQZU/CY Sav09Ewin10wBWNgWHOgXuJPqEsjOE1bFVhrn8LwSH4TCFRTI0M= =HIe0 -----END PGP SIGNATURE----- --Il7n/DHsA0sMLmDu--