SCOUG-Programming Mailing List Archives
Return to [ 12 |
September |
2006 ]
>> Next Message >>
Content Type: text/plain
This has been a problem here for years and I think I've just figured out
_what_ is happening but have no idea how to resolve it. Ideas?
_____
Problem: My own Rexx programs which use SysSleep() "wake up" a tad
early, for example 10 seconds too early if they sleep for 12 hours. In
other words, if I SysSleep() for 12 hours beginning at 3:00:00, I might
wake up at 2:59:50.
Apparent Reason: I use an NTP program to keep my system clock set, and
my cpu clock is a little fast. In my case I use OS2NTPD which adds a
half-cycle to the Real Time Clock (RTC) when necessary (other NTP
programs just reset the clock sporadically). And my cpu clock runs
fast, iirc it adds about 40 seconds every 24 hours if OS2NTPD isn't
running.
Analysis: Since my cpu runs fast, OS2NTPD "slows down the RTC" every
now and then by a half-cycle (1/120 second). But the cpu clock is still
running at its slightly-fast speed so it will reach the equivalent of
3:00:00 _before_ the RTC does (since the RTC is being slowed down).
That's apparently why I "wake up" too soon -- and if my cpu clock ran
slow instead of fast then I would wake up a little late instead of a
little early.
I don't know if cron and other timer programs have a similar problem, I
haven't tested them.
I do need to do further testing with OS2NTPD turned off, to see if I
then "wake up" on time. But I need some insight into how SysSleep()
actually works so I can design the tests.
Question #1: My guess is that SysSleep() isn't using the RTC. Anybody
know what it uses, or what "timer" calls are available in the OS/2 API?
Question #2: Does anybody have a workaround for the situation where the
cpu clock isn't exact and an NTP program is occasionally resetting the
RTC clock? I'd like to test any workarounds.
Question #3: Has this problem surfaced on other platforms, such as *nix
or Windows?
Question #4: There is a conceptual difference between SysSleep() which
"waits a specific amount of time" and a hypothetical SleepUntil() or
WakeUpAt() which wait for a specific match with the system clock. Are
there any calls, on any platform, for the hypothetical
SleepUntil()/WakeUpAt()? If so, I'd like to research them.
Somebody is probably going to ask, "Why do you care?" I have a
radio-broadcast-over-internet project I'm working on and it requires 1/2
second resolution. Waking up too early or too late is a problem.
(One possible workaround: SysSleep() for half the desired time, then
recalculate the remaining sleep time based on the current RTC value and
repeat until the desired clock time is reached.)
Yes I know that Daylight Saving boundaries are a problem on OS/2. I'll
deal with that one later.
- Peter
=====================================================
To unsubscribe from this list, send an email message
to "steward@scoug.com". In the body of the message,
put the command "unsubscribe scoug-programming".
For problems, contact the list owner at
"postmaster@scoug.com".
=====================================================
>> Next Message >>
Return to [ 12 |
September |
2006 ]
The Southern California OS/2 User Group
P.O. Box 26904
Santa Ana, CA 92799-6904, USA
Copyright 2001 the Southern California OS/2 User Group. ALL RIGHTS
RESERVED.
SCOUG, Warp Expo West, and Warpfest are trademarks of the Southern California OS/2 User Group.
OS/2, Workplace Shell, and IBM are registered trademarks of International
Business Machines Corporation.
All other trademarks remain the property of their respective owners.
|