Re: NSTimer fires ~0.0045 seconds early?
Re: NSTimer fires ~0.0045 seconds early?
- Subject: Re: NSTimer fires ~0.0045 seconds early?
- From: "Michael A. Crawford" <email@hidden>
- Date: Mon, 06 Aug 2001 21:22:24 -0700
On 8/6/01 9:23, "Brant Vasilieff" <email@hidden> wrote:
>
According to the NSTimer docs:
>
>
> "When the timer's time limit has elapsed, the NSRunLoop fires the timer
>
> (causing its message to be sent), then checks for new input. Because of
>
> the various input sources a typical run loop manages, the effective
>
> resolution of the time interval for an NSTimer is limited to on the
>
> order of 50-100 milliseconds."
>
>
I understand that because timers are fired from the run loop, that they
>
wouldn't be able to guarantee to fire exactly on time, and that there
>
would be a slight latency. What I wasn't expecting was for them to
>
cheat and fire early.
>
Fire early? How early, how do you configure this in a way that accurately
accounts for latency in the system?
Almost no one implements timers this way. All of the timer code I've ever
read (or written, for that matter) expires the pending timer based on the
time-out value (delta between the time the timer was created and the time in
the future it should fire) elapsing. It is just much simpler that way.
Your average implementation of a delta-list (list of timer objects sorted in
expiration order, tracking the deltas between them) checks for equal-to or
less-than when the timer interrupt fires or the cycling thread checks the
current time (depends on your implementation).
It's not that what you propose can't be done. It can. It just doesn't seem
practical, at least not on a dynamic system with a constantly changing load.
If your timing is really that critical you probably need to implement
something in the kernel using a KEXT or move to real-time OS, where latency
is more deterministic.
My intention is not to be critical of you or what you're trying to
accomplish. I'm only suggesting that you relax your requirements if
possible or move to a different facility. NSTimer doesn't sound like it is
going to work for you.
-Michael