gpt4 book ai didi

grand-central-dispatch - 将优先级设置为 NSOperationQueue

转载 作者:行者123 更新时间:2023-12-04 15:24:06 24 4
gpt4 key购买 nike

GCD 允许根据 4 个全局优先级队列(高、默认、低、背景)将 block 分派(dispatch)到队列。
我的应用程序中有几个 NSOperationQueues,但希望以不同的优先级运行每个。据我了解 NSOperationQueue 是对 GCD 的抽象,并且希望为 NSOperationQueue 设置不同的优先级(类似于 GCD 优先级队列)。有没有办法这样做? (发现可以为操作设置优先级,但不能为队列本身设置优先级)。

最佳答案

从 iOS 8 开始,NSOperationQueue 有一个 qualityOfService属性(property),这就是我认为OP的意思。来自 Class Reference :

This property specifies the service level applied to operation objects added to the queue. If the operation object has an explicit service level set, that value is used instead. [...]

Service levels affect the priority with which operation objects are given access to system resources such as CPU time, network resources, disk resources, and so on. Operations with a higher quality of service level are given greater priority over system resources so that they may perform their task more quickly. You use service levels to ensure that operations responding to explicit user requests are given priority over less critical work.



同样在 iOS 8 中,您可以使用 underlyingQueue 更改使用哪个 GCD 队列。属性,因此选择具有所需优先级的全局 GCD 队列。

关于grand-central-dispatch - 将优先级设置为 NSOperationQueue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15907527/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com