多个 NSOperationQueues?

发布于 2024-08-28 02:26:08 字数 155 浏览 3 评论 0原文

我想在我的应用程序中使用 NSOperations 来解决线程问题。我已经阅读了一些教程,现在我知道我必须做什么,但我有一个问题。每个类中必须有相同的NSOperationQueue。如果我在每个类中使用新的 NSOperationQueue 会怎样?会出现并发问题吗?

I would like to use NSOperations in my application to resolve threading problems. I have read some tutorials and now I know what I have to do, but I have a problem. There is a must to have the same NSOperationQueue in each class. What if I use a new NSOperationQueue in each class. There will be concurrency problems?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

仲春光 2024-09-04 02:26:08

仅当您从多个线程访问资源时才会出现并发问题。如果您的操作不共享某些资源,即使运行多个 NSOperationQueue(NSOperationQueue 确实在内部运行多个线程),您也应该没问题。

如果您在多个线程之间共享一个 NSOperationQueue,您可能应该同步对其的调用(使用 @synchronized(...))。

You only have concurrency issues if you access a resource from more than one thread. If your operations do not share some resources you should be fine, even with more than one NSOperationQueue running (NSOperationQueue does internally run more than one thread anyway).

If you share one NSOperationQueue across multiple threads, you should probably synchronize calls to it (using @synchronized(...)).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文