开发者

Why is performSelector:onThread:withObject:waitUntilDone: not recommended for frequent inter-thread communication

Apple's Threading Programming Guide states that:

Although good for occasional communication between threads, you should not use the performSelector:onThread:withObject:waitUntilDone: method for time critical or frequent communi开发者_如何学JAVAcation between threads.

Which begs the questions: Which is, then, the acceptable method for frequent inter-thread communication, and why is performSelector:onThread:withObject:waitUntilDone: specifically not recommended.

ps: Not waiting until done, naturally.


The reason they don’t recommend using that probably is because this has a lot of overhead. Also it works only with threads that have a NSRunloop running. It’s really good for updating the UI from a secondary thread though.

For more heavy duty lifting you should use shared memory (with locks or lockless algorithms) for inter-thread-communication. Or even better use something like NSOperationQueue or Grand Central Dispatch and don’t worry about doing the communication and synchronization yourself, if your problem permits that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜