-1

according to apple's doc, tasks are still started in the order in which they were added to a concurrent queue, so it seems to me that there is no difference between a concurrent queue vs a serial queue where all its task are run by async.

correct me if I miss something

read bunch of documents and did not find the answer

1 Answer 1

0

The difference is how many tasks may run at the same time:

A serial queue only processes (runs) one task at time, one after another. A concurrent queue may process multiple tasks (on multiple thread) at the same time.

You typically use a serial queue to ensure only one task is accessing a resource at the same time. These are scenarios where you would traditionally use mutexes.

If you have tasks that would benefit from (and are able to) running concurrently at the same time, or tasks that are completely independent and thus don't care, you usually use a concurrent queue.

2
  • so if I run below code serialQueue.async {A},serialQueue.async {B},serialQueue.async {C} A,B,C are started in order, but they are executed in parallel, my question is: isn't that essentially what the con concurrent queue is doing in iOS? Feb 2 at 23:55
  • @Flowriverdrytree: No, with a serial queue they are started in order and run one after another (serially, not parallel). Task B is only started after after task A has completed, and task C is only started after B is completed. A concurrent queue allows all three tasks to run at the same time (concurrently/parallel).
    – DarkDust
    Feb 3 at 7:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.