• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Accuracy of timers?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Accuracy of timers?
      • From: "Eric E. Dolecki" <email@hidden>
References: 
 >Accuracy of timers? (From: "Eric E. Dolecki" <email@hidden>)
 >Re: Accuracy of timers? (From: Wade Tregaskis <email@hidden>)

  • Prev by Date: Re: Accuracy of timers?
  • Next by Date: Re: Core Data Fetches + Transient Properties + NSPredicateEditor = Sadness
  • Previous by thread: Re: Accuracy of timers?
  • Next by thread: Re: Accuracy of timers?
  • Index(es):
    • Date
    • Thread