Re: NSTimer questions
Re: NSTimer questions
- Subject: Re: NSTimer questions
- From: Christoffer Lerno <email@hidden>
- Date: Thu, 23 Sep 2004 10:23:05 +0200
On Sep 23, 2004, at 02:35, Steve Checkoway wrote:
On Sep 22, 2004, at 2:50 PM, Christoffer Lerno wrote:
One might suppose that running a select with say 1 microsecond, could
work. That way one could yield repeatedly until (for example) 10 ms
has passed. Unfortunately, running a select seems to take a minimum
of 10 ms no matter what delay I enter, this delay might in some cases
extend to 50 ms.
Last I heard, OS X had a scheduling granularity of 10 ms. If you
absolutely must do something at a particular time, you could busy
wait, but that's a bad idea for just about anything other than spin
locks.
That pretty much is in agreement with my tests.
After timing:
* usleep
* NSThread sleepUntilDate
* NSTimer scheduledTimerWithTimeInterval:invocation:repeats:
* select
* OpenGL sync
I can only conclude that the best timing you can get on a thread is
about 1/30th of a second. This is with very, very minor load. You can
quickly have this going to 1/10th of a second if one is unlucky (moving
the pointer seems to do the trick).
Maybe I should add that this is without any processing whatsoever, I'm
just measuring the longest delay you might expect from a yielding
thread regardless of how long delay you asked for.
Basically as soon as you set a sleep or something on your thread, you
have to expect that other threads might add 10 to 100 ms extra from
that sleep. And that would be ok IF there was any heavy load on the
processor, but this happens when all processes are pretty much idle.
Within a 3 second period, regardless of what method you use to delay
the process, there will be at least one delay which will take 30 ms or
more* regardless of load.
(* on my iBook G3 800MHz)
Since there is no load whatsoever, this is a problem with the scheduler
rather than anything else.
The only way to avoid this is to busy-wait in the thread (which isn't
really an option).
Is there then no way to tell the scheduler that it is really, really
important that my sleep doesn't exceed the number I've given? It seems
like any animation at an fps higher than 20 is doomed to fail to
achieve smoothness on os x.
Surely this can't be right?
/Christoffer
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden