Synchronization/wait design for cross-thread event signaling (Obj-C)?

后端 未结 2 484
太阳男子
太阳男子 2021-01-14 17:52

In a Cocoa app, I have a setup like this:

  1. The main thread (M) can submit requests to a some background \"producer\" thread (B) to get some work done, say the r
2条回答
  •  爱一瞬间的悲伤
    2021-01-14 18:03

    If possible, use NSOperation. It has a -waitUntilFinished method to allow for synchronous computation. You'd just need some thread-safe storage mechanism to allow you to find the NSOperation for the item you're computing, if it already exists—say, an NSLock guarding an NSDictionary.

提交回复
热议问题