NSOperationQueue串行FIFO队列 [英] NSOperationQueue serial FIFO queue

查看:547
本文介绍了NSOperationQueue串行FIFO队列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将 NSoperationQueue 对象用作串行FIFO队列,方法是将 maxConcurrentOperationCount 设置为1?

Is it possible to use an NSoperationQueue object as a serial FIFO queue by setting its maxConcurrentOperationCount to 1?

我注意到 docs state ...

I note that the docs state...


对于最大并发操作数设置为1的队列,这等同于到一个串行队列。但是,您永远不应该依赖于操作对象的串行执行。

For a queue whose maximum number of concurrent operations is set to 1, this equates to a serial queue. However, you should never rely on the serial execution of operation objects.

这是否意味着无法保证FIFO执行?

Does this mean that FIFO execution is not guaranteed?

推荐答案

在大多数情况下,它将是FIFO。但是,您可以在NSOperations之间设置依赖关系,以便提前提交的操作将允许其他操作在队列中传递它,直到其依赖关系得到满足。

In most cases, it will be FIFO. However, you can set up dependencies between NSOperations such that an operation submitted early will let other operations pass it by in the queue until its dependencies are satisfied.

此依赖关系管理是为什么文档表明无法保证FIFO-ness。但是,如果您不使用依赖项,则可以依赖它。

This dependency management is why the docs indicate that FIFO-ness cannot be guaranteed. If you're not using dependencies, though, you should be fine to rely on it.

更新
NSOperation也有一个 queuePriority 属性,它也可以使操作以非FIFO顺序执行。没有挂起依赖项的最高优先级操作将始终首先执行。

Update: NSOperation also has a queuePriority property, which can also cause operations to execute in non-FIFO order. The highest-priority operation with no pending dependencies will always execute first.

NSOperation子类也可能会覆盖 -isReady ,这可能会导致它回到队列中。

An NSOperation subclass might also override -isReady, which could cause it to move back in the queue.

因此,队列上的执行保证是 serial ,因此不会超过一个操作将在此队列中一次运行。但Apple无法保证FIFO;这取决于你对所投入的操作做了什么。

So execution on your queue is guaranteed to be serial, in that no more than one operation will run at a time in this queue. But Apple can't guarantee FIFO; that depends on what you're doing with the operations you put in.

这篇关于NSOperationQueue串行FIFO队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆