• 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: timers
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: timers


  • Subject: Re: timers
  • From: Doug Wyatt <email@hidden>
  • Date: Mon, 13 Aug 2001 08:38:46 -0700

On Monday, August 13, 2001, at 05:52 , James McCartney wrote:
on 8/13/01 3:23 AM, Markus at email@hidden wrote:


Am Montag, 13. August 2001 um 05:41 schrieb James McCartney:

But what should you use to fire off a function at a certain time?

NSTimer does this easily. Drawback is, it fires from within the Run
Loop, which leads to poor resolution if you do heavy calculations in the
main thread (but this should be avoided anyway).

How does NSTimer compare with Time Manager or usleep for latency,
resolution? Or perhaps pthread_cond_wait? (it's the only thing I can find
using struct timespec - no nanosleep() call in OSX ?)

A recent ADC News item points to:

TN2028 - Threading Architectures
http://developer.apple.com/technotes/tn/tn2028.html

NSTimer is built on the CoreFoundation CFRunLoop/runloopsource. The source is in Darwin so one could see what's going on under the covers there. It's possible that the timer resolution could be higher than you'd like; I'm just guessing. The wakeup latency will be a function of the resolution of the wakeup timer and the priority of the runloop's thread vs. what other threads -- and other sources on that runloop -- it's competing with.

I wouldn't recommend usleep() (the man page has an interesting note ...).

I confess to having no idea what kind of performance you'd get with the Carbon Time Manager, but (since I believe you're an old-timer who could do this in 10 minutes) you could write a test program, and then look at its threads (ps axM) to see what kind of priority they're getting.

pthread_cond_wait is a pretty direct way to tell the scheduler you want to run a thread at some exact time in the future, and the wakeup latency will be a direct function of your thread's priority vs. that of the other runnable threads.

hth,
Doug

--
Doug Wyatt
work: email@hidden (CoreAudio)
personal: email@hidden http://www.sonosphere.com

"When you discard arrogance, complexity, and a few other things that get in
the way, sooner or later you will discover that simple, childlike, and
mysterious secret known to those of the Uncarved Block: Life is Fun."
-- The Tao of Pooh


  • Follow-Ups:
    • Re: timers
      • From: James McCartney <email@hidden>
References: 
 >Re: timers (From: James McCartney <email@hidden>)

  • Prev by Date: Re: timers
  • Next by Date: Re: timers
  • Previous by thread: Re: timers
  • Next by thread: Re: timers
  • Index(es):
    • Date
    • Thread