X-Recipient: archive-cygwin@delorie.com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
	:list-unsubscribe:list-subscribe:list-archive:list-post
	:list-help:sender:date:from:to:cc:subject:message-id:reply-to
	:references:mime-version:content-type:in-reply-to; q=dns; s=
	default; b=OX+JdokUqYMKpx8gjrViq2TmP6ZQYrvM2u2VUoRF38rG/77CgfKrj
	KFrbZaBOQbH0/ltrrnXwBuZpp5FD/Y5hHXsLqcxueWJOX+foIlDTP3Wt1XCG5DsF
	UHSjrP/fMhx7wwW3M5EuCkq+3V9nQ0vk6vS9UkW4xlJYonvmCOnES8=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
	:list-unsubscribe:list-subscribe:list-archive:list-post
	:list-help:sender:date:from:to:cc:subject:message-id:reply-to
	:references:mime-version:content-type:in-reply-to; s=default;
	 bh=H24Kzghq3EPBDx5QgBVGNkxhzRE=; b=HJU9y7xRm5qkBa7AsgdOYLWmar5C
	pTs2B2VwDaV3oOoAg8TX1mTLWOAZDdzPcl4HL2+TO3SSGg+6crcitsYfTLpQPNu1
	0zUTCUKYoaOtfyK344hR6DUuRy75mtoFnhb2HnrRAYO0W7UC42IaRLnwMarNSBb0
	9Q9lWvt7b3v5eBE=
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com
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
Date: Thu, 29 Nov 2018 11:18:21 +0100
From: Corinna Vinschen <corinna-cygwin@cygwin.com>
To: cygwin@cygwin.com
Cc: "James E. King III" <jking@apache.org>
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" <jking@apache.org>
References: <CAOWZHxdTpDD6LLVctvjFQWqQMd9cex7pp-s1YYaMAdtGECy3Yw@mail.gmail.com> <20181126153545.GM30649@calimero.vinschen.de> <CAOWZHxdmOeQ7o6099PERwq-FbFbdYLLm43JfR5iQm-HtfP90aw@mail.gmail.com> <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)

--aiCxlS1GuupXjEh3
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

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
> > <corinna-cygwin@cygwin.com> 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"

-----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--
