Bil*_*ill 5 macos grand-central-dispatch ios
In GCD, there are two ways I can run blocks concurrently.
I can use one of the global pools:
DispatchQueue.global().async() {
// do work
}
Run Code Online (Sandbox Code Playgroud)
or I can create my own queue:
let queue = DispatchQueue(label: "process images", attributes: [.concurrent])
queue.async {
// do work
}
Run Code Online (Sandbox Code Playgroud)
but I can't find much information on when to prefer one over the other.
Some places (including this summary of mailing list posts from the libdispatch maintainer) suggest that you really shouldn't use the global queues.
Yet most code examples just dispatch to a global queue, and there are even some sources that say you really shouldn't use custom queues - and should prefer the global queues.
每种队列哪种情况更好?与此相关的是,有些文章建议优先使用串行队列而不是并发队列-但显然它们具有完全不同的并行性,因此很奇怪地看到它们建议可互换。
除了担心效率和线程爆炸,有了自己的并发队列,你还可以:
对于全局并发队列,这些都不可能。
| 归档时间: |
|
| 查看次数: |
311 次 |
| 最近记录: |