• 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: Notifications on main thread
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Notifications on main thread


  • Subject: Re: Notifications on main thread
  • From: James Bucanek <email@hidden>
  • Date: Tue, 2 Nov 2010 08:21:14 -0700

Jonny Taylor <mailto:email@hidden> wrote (Tuesday, November 2, 2010 3:01 AM -0000):

So, can anybody comment on all this? It seems like pretty bad news. Is this
what the release notes are saying, and if so, is there an alternative approach
that still lets me take advantage of the coalescing features of notification
queues?

I ran into this recently, and found it somewhat disconcerting, but I think the situation is simpler than described in the discussion link that you post.


It's my experience that queued notifications are posted _on the thread that enqueued the notification_.

See, it's not that complicated. It does seem to be independent of the notification queue and the notification center. Privately, I suspect that -[NSNotificationQueue enqueueNotification:...] works by pushing something to the run loop of the currently running thread, so it's this thread that processes the enqueue request, which implies which thread is running when the notification is dispatched. But that's entirely speculation.

Since -enqueueNotification:... has no parameter for specifying which run loop is used, the run loop is always implied by the current thread. My solution, in the situation where a background thread needs to queue a notification that will run on the main thread (or any thread), is to encapsulating the code that enqueues the notification in method and make sure that runs on the main thread via -performSelectorOnMainThread:, or something similar.

--
James Bucanek

_______________________________________________

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: Notifications on main thread
      • From: Jonny Taylor <email@hidden>
References: 
 >Re: Notifications on main thread (From: Jonny Taylor <email@hidden>)

  • Prev by Date: Re: Is NSStreamEvent a bitfield or not?
  • Next by Date: UITableView Selection
  • Previous by thread: Re: Notifications on main thread
  • Next by thread: Re: Notifications on main thread
  • Index(es):
    • Date
    • Thread