Re: Accuracy of timers?
Re: Accuracy of timers?
- Subject: Re: Accuracy of timers?
- From: Michael Ash <email@hidden>
- Date: Thu, 23 Apr 2009 09:12:31 -0400
On Thu, Apr 23, 2009 at 2:06 AM, Wade Tregaskis <email@hidden> wrote:
> P.S. For completeness I should mention of course nanosleep, but I don't know
> of its precision and in any case it can be interrupted by signals, which
> makes it more difficult to use than you'd expect.
Its precision is, of course, nanoseconds. The question is its
accuracy. I think the answer there is that it's as accurate as the
scheduler can make it, which will depend on system load.
Signal interruption is not very difficult at all. Essentially all you
have to do is stick the call in a loop. Unsafe code already has the
necessary calculations (pseudocode):
remainingTime = targetTime - now;
nanosleep(remainingTime);
So all you have to do is wrap it in a loop that keeps retrying:
while(1) {
remainingTime = targetTime - now;
if(remainingTime <= 0) break;
nanosleep(remainingTime);
}
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden