通过 [NSOperationQueue 操作] 进行枚举是否安全?
通过[NSOperationQueue操作]
通过快速枚举进行枚举是否安全?就像这样:
for (NSOperation *op in [operationQueue operations]) {
// Do something with op
}
由于操作是异步的并且在另一个线程上执行,因此操作可能随时更改(包括在主线程执行期间)。快速枚举是否可以防止这种情况,或者我应该复制(和自动释放)操作数组?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只有当您枚举数组时队列改变了数组,才是不安全的。
然而:
There 向我建议队列将为您执行复制和自动释放,以便您可以安全地枚举数组。
It's only unsafe if the queue mutates the array while you're enumerating it.
However:
The word “new” in there suggests to me that the queue will do the copy and autorelease for you, so you can safely enumerate through the array.