作者:初学 | 来源:互联网 | 2022-12-08 12:13
如何解决《InGCD,whendoIuseaglobalconcurrentqueuevsacustomconcurrentqueue?》经验,如何解决这个问题?
In GCD, there are two ways I can run blocks concurrently.
I can use one of the global pools:
DispatchQueue.global().async() {
// do work
}
or I can create my own queue:
let queue = DispatchQueue(label: "process images", attributes: [.concurrent])
queue.async {
// do work
}
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.
每种队列哪种情况更好?与此相关的是,有些文章建议优先使用串行队列而不是并发队列-但显然它们具有完全不同的并行性,因此很奇怪地看到它们建议可互换。