iPhone 线程同步
我是 Java 开发人员,需要在 iPhone 中进行线程同步。我有一个线程,它调用另一个线程,需要等待该子线程结束。 在java中我通过调用wait/notify使用监视器
如何在iphone中对此进行编程?
谢谢
I am java developer and need to make thread synch in iPhone. I have a thread, it calls other one and need to wait for that child thread to end.
In java I use monitor, by calling wait/notify
How can I program this in iphone?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
NSConditionLock 完成所有工作
NSConditionLock does all job
阅读
NSOperation
依赖项 以及NSNotification
通知。Read about
NSOperation
dependencies and alsoNSNotification
notifications.就我个人而言,我更喜欢 pthreads。要阻止线程完成,您需要
pthread_join
或者,您可以设置一个pthread_cond_t
并让调用线程等待,直到子线程通知它。Personally, I prefer pthreads. To block for a thread to complete, you want
pthread_join
Alternately, you could set up apthread_cond_t
and have the calling thread wait on that until the child thread notifies it.