
In the context of an NSOperation
object,the terms concurrent and
non-concurrent do not necessarily
refer to the sIDe-by-sIDe execution of
threads. Instead,a non-concurrent
operation is one that executes using
the environment that is provIDed for
it while a concurrent operation is
responsible for setting up its own
execution environment.
设置“自己的执行环境”是什么意思?
我的NSOperation派生任务需要按照它们被添加到队列的顺序连续执行。
所以我认为这意味着“非并发” *** 作,所以我将为需要完成的工作实现“主”,并且为“isConcurrent”返回否。另外,NSOperationQueue的’setMaxConcurrentoperationCount’将被设置为1。
我没有在这些任务之间设置NSOperation依赖的原因是因为它们插入到队列中的顺序是它们应该完成的顺序。
这些假设是否正确?
解决方法 NSOperationQueue总是同时执行 *** 作,同时考虑依赖关系。“并发” *** 作需要一个单独的线程才能同时执行。 NSOperationQueue负责提供这个线程。换句话说,非并发 *** 作取决于NSOperationQueue使其成为并发 *** 作。
“并发” *** 作是并发的;它不需要NSOperationQueue为它创建一个线程。一个例子是使用异步文件IO的 *** 作。
如果您希望两个或多个 *** 作顺序执行,则需要使用依赖关系。
如果想要一个 *** 作来阻止主线程,那么不要使用NSOperationQueue;在主线程上一个接一个地运行每个 *** 作。
要手动设置并发 *** 作的最大值,请在operationQueue上使用方法setMaxConcurrentoperationCount:
总结以上是内存溢出为你收集整理的iphone – NSOperationQueue和并发vs非并发全部内容,希望文章能够帮你解决iphone – NSOperationQueue和并发vs非并发所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)