- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
正如文档所说:
DISPATCH_QUEUE_PRIORITY_BACKGROUND Items dispatched to the queue will run at background priority, i.e. the queue will be scheduled for execution after all higher priority queues have been scheduled and the system will run items on this queue on a thread with background status as per setpriority(2) (i.e. disk I/O is throttled and the thread’s scheduling priority is set to lowest value).
文档的最后一部分,"disk I/O is throttled"
在这里是什么意思?
这是否意味着在 DISPATCH_QUEUE_PRIORITY_BACKGROUND
级别运行的任务无法访问磁盘?
最佳答案
我们可以从文档中推断出 DISPATCH_QUEUE_PRIORITY_BACKGROUND
是在一个线程上运行的,“后台状态根据 setpriority(2) ”。
setpriority(2)有一个参数 prio
,可以设置为 0
或 PRIO_DARWIN_BG
。我认为这意味着使用了 PRIO_DARWIN_BG
并且文档将其描述为:
When a thread or process is in a background state the scheduling priority is set to the lowest value, disk IO is throttled (with behavior similar to using setiopolicy_np(3) to set a throttleable policy), and network IO is throttled for any sockets opened after going into background state. Any previously opened sockets are not affected.
setiopolicy_np(3)可以将线程 I/O 策略设置为 IOPOL_IMPORTANT
、IOPOL_STANDARD
、IOPOL_UTILITY
、IOPOL_THROTTLE
或 IOPOL_PASSIVE
。它将节流磁盘 I/O 的影响描述为:
If a throttleable request occurs within a small time window of a request of higher priority, the thread that issued the throttleable I/O is forced to a sleep for a short period. (Both this window and the sleep period are dependent on the policy of the throttleable I/O.) This slows down the thread that issues the throttleable I/O so that higher-priority I/Os can complete with low-latency and receive a greater share of the disk bandwidth. Furthermore, an IMPORTANT I/O request may bypass a previously issued throttleable I/O request in kernel or driver queues and be sent to the device first. In some circumstances, very large throttleable I/O requests will be broken into smaller requests which are then issued serially.
这基本上意味着如果另一个具有更高优先级的线程也在访问磁盘,那么读写磁盘可能会变慢或延迟。所以不,它不会阻止在 DISPATCH_QUEUE_PRIORITY_BACKGROUND
上运行的任务访问磁盘。
关于iOS GCD : DISPATCH_QUEUE_PRIORITY_BACKGROUND, 文档中的 "disk I/O is throttled"是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27188804/
我是一名优秀的程序员,十分优秀!