• 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: Grand Central Dispatch vs CFRunLoop
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Grand Central Dispatch vs CFRunLoop


  • Subject: Re: Grand Central Dispatch vs CFRunLoop
  • From: Ken Thomases <email@hidden>
  • Date: Sun, 13 Sep 2009 23:18:16 -0500

On Sep 13, 2009, at 10:09 AM, Filip van der Meeren wrote:

I am using NSTask objects in a Command Line Tool project, to be able to intercept notifications I need a runloop to the best of my knowledge.

Don't confuse two different things. Notifications do not require a run loop in order to be delivered. The observer's selectors are just directly invoked when the notification is posted.


However, NSTask has to monitor an external event in order to determine when the task has terminated. For that, it installs a run loop source into the run loop of the thread from which it is launched.

Once it has determined that the task has terminated, NSTask does post a notification. But it's the monitoring of the task that requires the run loop to be run, not the delivery of the notification.


And ever since I installed Mac OS X 10.6, I wondered if I could replace that entire runloop by a dispatch_queue.

That's thinking about things the wrong way around. A run loop is a higher-level abstraction than a dispatch queue. In general, you should always program in terms of the highest-level abstraction that suits your purposes. So, you _want_ to run the run loop instead of running the dispatch queue manually. As documented for dispatch_get_main_queue(), running the main thread's run loop automatically processes the main dispatch queue.


With respect to NSTask, there's no reason to believe that it will work if you just run the main dispatch queue rather than running the NSRunLoop. I highly doubt it would.

Regards,
Ken

_______________________________________________

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


  • Follow-Ups:
    • Re: Grand Central Dispatch vs CFRunLoop
      • From: Chris Kane <email@hidden>
References: 
 >Grand Central Dispatch vs CFRunLoop (From: Filip van der Meeren <email@hidden>)

  • Prev by Date: Re: Circular references
  • Next by Date: re: CoreData multiple contexts and threads
  • Previous by thread: Grand Central Dispatch vs CFRunLoop
  • Next by thread: Re: Grand Central Dispatch vs CFRunLoop
  • Index(es):
    • Date
    • Thread