At 22:44 -0700 19/10/10, Chris Hanson wrote: >On Oct 19, 2010, at 12:41 PM, Rainer Brockerhoff wrote: > >> A too-low value will make your thread activate too often (making it use more >> CPU when idle) and a too-high value will make it too slow to react to >> "condition" being set to NO. I usually set something between 0.5 and 1; it's >> optimal in the sense "works-for-me" ;-) > >Rather than do that, create another, custom CFRunLoopSource that can be used >to wake up the run loop (via CFRunLoopSourceSignal) when the condition changes. > >Then instead of just > > condition = NO; > >use > > condition = NO; > CFRunLoopSourceSignal(mySource); > >to wake the run loop immediately. That'll let you set a nice high timeout >rather than something low like 0.5 or 1, and prevent you from wasting CPU.
Good point Chris. When I first used that code, I had a more complex condition to poll (not just a single BOOL). For the simplified case, the custom source is most efficient. -- Rainer Brockerhoff <rai...@brockerhoff.net> Belo Horizonte, Brazil "In the affairs of others even fools are wise In their own business even sages err." Blog: http://brockerhoff.net/blog _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com