在 iOS 中暂停特定线程?
在我的 iPhone 应用程序中,我使用了 2 个线程。两者在不同类别中的功能不同。在特定条件下,我想暂停特定线程,因此我使用了[NSThread sleepForTimeInterval:]
所以我的问题是我做得对还是这个睡眠导致整个应用程序睡眠?如果是的话还有什么其他选择?
in my iPhone app, I have used 2 threads. Both functions differently in different class. On particular condition I want to pause particular thread so I have used[NSThread sleepForTimeInterval:]
So my question is am I doing right or this sleep causes sleep in whole application? If yes what is other alternative?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您想将线程暂停给定的时间,那么
[NSThread sleepForTimeInterval:]
就可以了。但是,如果您想等待给定事件发生(例如等待另一个线程赶上),您应该查看NSCondition
类。If you want to pause your thread for a given amount of time, then
[NSThread sleepForTimeInterval:]
is just fine. However if you want to wait for a given event to occur (e.g. wait for another thread to catch up) you should take a look at theNSCondition
class.是的,这是绝对正确的。这将暂停您正在调用的当前线程
[NSThread sleepForTimeInterval:]
Yeah this is absolutely right. This will pause the current thread on which you are calling
[NSThread sleepForTimeInterval:]