Re: Background Process?
Re: Background Process?
- Subject: Re: Background Process?
- From: Roland King <email@hidden>
- Date: Wed, 11 Mar 2009 13:53:43 +0800
Kyle Sluder wrote:
On Tue, Mar 10, 2009 at 11:38 PM, Michael Ash <email@hidden> wrote:
The notion that adding a timer to a runloop would somehow cause that
runloop to suck up CPU time when the runloop is idle is nonsensical.
The whole point of the runloop is that it sleeps the process until
some activity is required. A background process sitting on a timer
*will* take up various resources (memory, file descriptors, kernel
structures, etc.) but CPU time is not among them.
That's not what I said. What I said was that you cannot add a timer
to your runloop and expect it to sit blocking on it until the timer
fires. That's not how timers operate. You will need to periodically
run the runloop in order to get your timer to fire. If you are doing
this in an application, then the event-processing functionality of the
runloop will take care of it. Otherwise, you will need to run it
yourself. Either way, you will need to periodically poke the runloop,
which on it's face can't take 0.0% CPU. Your app will persistently
wake up (and our friend Nyquist has proven that in order for this to
work it must wake at least twice as often as you want the timer to
fire).
--Kyle Sluder
This isn't how I understood the runloop documentation when I read it,
and it's more than possible I have totally misread it. In the runloop
documentation it says that at step '7'
*Put the thread to sleep until one of the following events occurs:
An event arrives for a port-based input source
A timer fires
The timeout value set for the runloop expires
The runloop is explicitly woken up.*
So you just add the timer to the runloop, run it, it sleeps until the
timer fires, does its thing and then goes back to sleep again. What am I
missing?
_______________________________________________
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