等待并通知Objective c中的等效内容? [英] Wait and notify equivalent in Objective c?

查看:97
本文介绍了等待并通知Objective c中的等效内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将程序从java转移到Objective C,并且需要使用等待和通知方法,这些方法经常用于java中的线程,但似乎无法在Objective C中找到任何好的等价物。我尝试过使用NSLock对象但我不认为它有效。 (我正在使用[NSLock lock]进行等待,并且[NSLock unlock]用于通知)在Objective C中是否存在我无法找到的任何好的等价物?

I am transferring a program from java to Objective C and need to use wait and notify methods that are frequently used for threading in java but can't seem to find any good equivalent in Objective C. I've tried using NSLock object but I don't think it is working. (I'm using [NSLock lock] for waits and [NSLock unlock] for notifies) Is there any good equivalent in Objective C that I haven't been able to find?

推荐答案

您可以使用多种技术。您可以使用NSCondition或POSIX信号量或分派信号量或使用运行循环。查看并发指南线程指南

There are numerous techniques you could use. You can use NSCondition or POSIX semaphores or dispatch semaphores or by using run loops. Check out the Concurrency Guide and the the Threading Guide.

我个人最喜欢的是 dispatch semaphore

这篇关于等待并通知Objective c中的等效内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆