Re: Accuracy of timers?
Re: Accuracy of timers?
- Subject: Re: Accuracy of timers?
- From: "Eric E. Dolecki" <email@hidden>
- Date: Thu, 23 Apr 2009 10:27:36 -0400
Thanks for all the great feedback.
Eric
On Thu, Apr 23, 2009 at 9:12 AM, Michael Ash <email@hidden> wrote:
> 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
>
--
http://ericd.net
Interactive design and development
_______________________________________________
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