Is NSNotificationCenter thread safe?

不打扰是莪最后的温柔 提交于 2019-12-21 03:52:25

问题


Can I post a notification in a given queue and receive it on another? I want to use notifications to communicate different queues, but I'm not sure if this is safe...


回答1:


No. Notifications are delivered in the same thread that they are sent from, this you will need to re-send it in some way to get the notification to your thread.




回答2:


No.

Apple's docs on the subject say: "Regular notification centers deliver notifications on the thread in which the notification was posted. [...] At times, you may require notifications to be delivered on a particular thread that is determined by you instead of the notification center. [...] In these cases, you must capture the notifications as they are delivered on the default thread and redirect them to the appropriate thread."

The following documentation from Apple might help: https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Notifications/Articles/Threading.html#//apple_ref/doc/uid/20001289-CEGJFDFG



来源:https://stackoverflow.com/questions/15968430/is-nsnotificationcenter-thread-safe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!