线程可以与队列类似地使用,还是它们意味着不同的事物?
Can thread be used analogously with queue, or do they mean separate things?
我正在阅读 this 很棒的教程,当我遇到以下行时(作为背景:我们正在学习如何使用 dispatch_apply
替换 for
循环并同时下载照片):
Be aware that although you have code that will add the photos in a thread safe manner, the ordering of the images could be different depending on which thread finishes first.
出于某种原因,这句话真的让我失望了。我认为 dispatch_apply
将 运行 一个 并发线程 、GlobalUserInitiatedQueue
上的任务,而不是多个不同的线程。他通过以下方式调用该方法:
dispatch_apply(addresses.count, GlobalUserInitiatedQueue) {
那么GlobalUserInitiatedQueue
是单线程,还是多线程,线程和队列有什么区别?从表面上看,它们的用法类似。这是否意味着并发队列同时有多个线程 运行ning?
谢谢-
来自指南:
"Concurrent queues (also known as a type of global dispatch queue)
execute one or more tasks concurrently, but tasks are still started in
the order in which they were added to the queue. The currently
executing tasks run on distinct threads that are managed by the
dispatch queue. The exact number of tasks executing at any given point
is variable and depends on system conditions."
再清楚不过了。多线程,按照队列中任务的顺序开始,但没有特定的顺序结束。
我喜欢教程和 material 旨在详细解释内容的教程。但是,当有疑问时,我总是会回到 Apple 官方文档。
我正在阅读 this 很棒的教程,当我遇到以下行时(作为背景:我们正在学习如何使用 dispatch_apply
替换 for
循环并同时下载照片):
Be aware that although you have code that will add the photos in a thread safe manner, the ordering of the images could be different depending on which thread finishes first.
出于某种原因,这句话真的让我失望了。我认为 dispatch_apply
将 运行 一个 并发线程 、GlobalUserInitiatedQueue
上的任务,而不是多个不同的线程。他通过以下方式调用该方法:
dispatch_apply(addresses.count, GlobalUserInitiatedQueue) {
那么GlobalUserInitiatedQueue
是单线程,还是多线程,线程和队列有什么区别?从表面上看,它们的用法类似。这是否意味着并发队列同时有多个线程 运行ning?
谢谢-
来自指南:
"Concurrent queues (also known as a type of global dispatch queue) execute one or more tasks concurrently, but tasks are still started in the order in which they were added to the queue. The currently executing tasks run on distinct threads that are managed by the dispatch queue. The exact number of tasks executing at any given point is variable and depends on system conditions."
再清楚不过了。多线程,按照队列中任务的顺序开始,但没有特定的顺序结束。
我喜欢教程和 material 旨在详细解释内容的教程。但是,当有疑问时,我总是会回到 Apple 官方文档。