This is the mail archive of the cygwin-developers mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: timeBeginPeriod considered harmful


At 06:16 PM 11/12/2005 -0500, Christopher Faylor wrote:
>On Fri, Nov 11, 2005 at 05:47:17PM -0500, Pierre A. Humblet wrote:
>>I worked on the resolution issue a while back, to insure the following
>>Posix behavior (exim relies on it):
>>If you 1) call time() or equivalent, 2) sleep() or alarm() for some
>>interval, 3) call time() again, then the difference between the times in
>>3) and 1) cannot be smaller than the interval in 2).  Insuring that is
>>easier if the resolution is known.
>>I am not sure if Cygwin still behaves that way, insuring it requiring
>>rounding up at various places.
>
>I was thinking about the above in the thinking room today and it
>occurred to me that the right way (tm) to fix this problem would be to
>modify sleep/alarm so that the above is true.  alarm might be slightly
>trickier than sleep but I don't think it would be unbelievably hard.  It
>seems like adding a low_priority_sleep loop to nanosleep and alarm which
>waits until the time delta was >= what was expected would be preferable
>to forcing the resolution to 1ms for the whole program forever.

I was just indicating what I had done with the time routines, this is not
directly related to the 1 ms resolution (it was there before, as I recall).
No matter what the resolution is, it should be possible to get it and do
the right thing, for example in nanosleep:
  DWORD resolution = gtod.resolution ();
  DWORD req = ((rqtp->tv_sec * 1000 + (rqtp->tv_nsec + 999999) / 1000000
                + resolution - 1) / resolution) * resolution;
Your approach can surely also be made to work.
I will take another look this week, on WinME and XP.

Pierre


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]