• 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: What's better a separate run loop or separate thread?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What's better a separate run loop or separate thread?


  • Subject: Re: What's better a separate run loop or separate thread?
  • From: Shawn Erickson <email@hidden>
  • Date: Sat, 10 Jul 2004 08:29:41 -0700

On Jul 10, 2004, at 2:12 AM, Ken Tozier wrote:

I have a number of processes that need to run constantly in the background while my app does other things and I'm wondering if it would be better to create dedicated run loops for them with NSTimers for the required methods or to fork a thread with a timer.

A run loop runs in a thread and only one exists per thread.

Your main thread is running one that is hooked up with event sources and started by NSApplication. You can schedule timers against this run loop but the processing will be done in your main thread when the timer call back takes place which may or may not cause it to become unresponsive to user input (not sure how long or intense the processing is that you want to do). Of course the call back could pass off the work to a back ground thread (I have done stuff like this using a custom built thread poll framework, one that keeps some amount of threads ready and can queue things if you put a limit on how many threads you want running).

So if it was me... I would fire up a new thread and depending on how you want to work with things start up a run loop in that thread with timers, and ports, etc. The documentation on NSRunLoop and the programming topics linked to from that documentation should be sufficient to do what is needed.

In particular... <http://developer.apple.com/documentation/Cocoa/Conceptual/ InputControl/Tasks/runningloops.html>

-Shawn
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


References: 
 >What's better a separate run loop or separate thread? (From: Ken Tozier <email@hidden>)

  • Prev by Date: Re: What's better a separate run loop or separate thread?
  • Next by Date: Model initiated change in bindings
  • Previous by thread: Re: What's better a separate run loop or separate thread?
  • Next by thread: Re: What's better a separate run loop or separate thread?
  • Index(es):
    • Date
    • Thread