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

后端 未结 2 487
太阳男子
太阳男子 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:12

    An NSConditionLock could work nicely here. Perhaps a condition lock associated with each X. Initially condition "dormant" then set to "processing" by the background thread then set to "complete" when it is done. The calling thread could check for the "processing" condition and if it is set, wait until condition "complete" is reached.

提交回复
热议问题