核心数据并发(NSOperation)
在Apple docs 中写道:
...您应该在中创建上下文 main(对于串行队列)或start (对于并发队列)。
但我真的不明白有什么区别。为什么我无法在 main
中为并发队列创建上下文?我尝试过,它的工作原理与我在 start
中所做的完全一样。
还有一件事让我很困惑。来自 启动方法:
...如果您正在实施 并发操作,你必须 覆盖此方法并使用它 启动您的操作。
那么,为什么我不能初始化 main
中的所有内容(或者也许不应该初始化)?
In Apple docs it is written:
...you should create the context in
main (for a serial queue) or start
(for a concurrent queue).
But I really don't get what is the difference. Why can't I create context in main
for the concurrent queue? I tried that and it works absolutely the same as if I did that in start
.
There is also another thing that confuses me. From docs for the start method:
...If you are implementing a
concurrent operation, you must
override this method and use it to
initiate your operation.
So again, why can't I initialize everything in main
(or maybe should not initialize)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您所说的“上下文”和“并发”与 Apple 对这些术语的含义可能有所不同。他们以一种特定的(并且令人困惑的)方式使用“并发”。 使用 NSOperation 管理并发 中的这一部分可能会有所帮助:
There may be a difference between what you're calling 'context' and 'concurrent' and what Apple means by the terms. They use 'concurrent' in a specific (and confusing) way. This section from Managing Concurrency With NSOperation might help:
没有理由不能在 main() 中为并发队列创建上下文,但由于您必须在 main() 中管理运行循环,因此如果您使用它,通常最好在 start() 中设置诸如上下文之类的东西技术。
There's no reason you can't create the context in main() for a concurrent queue, but since you have to manage a run loop in main it's usually nicer looking to set up things like a context in start() if you are using that technique.