public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: "James E. King III" <jking@apache.org>
To: cygwin@cygwin.com
Subject: Re: pthread_cond_timedwait with setclock(CLOCK_MONOTONIC) times out early
Date: Thu, 29 Nov 2018 22:39:00 -0000	[thread overview]
Message-ID: <CAOWZHxf+en-Nw20jOeeBu-TXBio07ai5ecJk2bvWDPtD0vqKFQ@mail.gmail.com> (raw)
In-Reply-To: <20181129101821.GZ30649@calimero.vinschen.de>

On Thu, Nov 29, 2018 at 5:18 AM Corinna Vinschen
<corinna-cygwin@cygwin.com> wrote:
>
> 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 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-functions#wait-functions-and-time-out-intervals
> > > >
> > > > --
> > > > Corinna Vinschen
> > > > Cygwin Maintainer
> > >
> > > Some thoughts:
> > >
> > > https://cygwin.com/git/gitweb.cgi?p=newlib-cygwin.git;a=blob;f=winsup/cygwin/thread.cc;h=0bddaf345d255ae39187458dc6d02b1b4c8087c1;hb=HEAD#l2546
> > >
> > > 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?
>
> I created a patch and uploaded new developer snapshots to
> https://cygwin.com/snapshots/  Please give them a try.
>
>
> Thanks,
> Corinna
>

This fixed the issue for me.  What's the best way to detect cygwin
with this support?
I see something around "has_precise_interrupt_time".  I suppose that
would be it?
I need to make some changes in Boost.Thread to accomodate it.

Thanks,

Jim

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

  reply	other threads:[~2018-11-29 22:39 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-25 14:01 James E. King III
2018-11-26 15:35 ` Corinna Vinschen
2018-11-26 15:47   ` James E. King III
2018-11-26 16:47     ` Corinna Vinschen
2018-11-29 10:18       ` Corinna Vinschen
2018-11-29 22:39         ` James E. King III [this message]
2018-11-30 12:14           ` Corinna Vinschen
2018-11-30 12:44             ` James E. King III
2018-11-30 12:56               ` Corinna Vinschen
2018-12-01  4:27                 ` Brian Inglis
2018-12-01  9:53                   ` Corinna Vinschen
2018-12-01 15:49                     ` Brian Inglis
2018-12-02 11:34                       ` Corinna Vinschen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAOWZHxf+en-Nw20jOeeBu-TXBio07ai5ecJk2bvWDPtD0vqKFQ@mail.gmail.com \
    --to=jking@apache.org \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).