Concurrent dispatch queue:
func myConcurrentQueue() {
let concurrentQueue = DispatchQueue(label: "concurrent", attributes: .concurrent)
concurrentQueue.async {
print("Task 1 Con Start")
print("Task 1 Con Finished")
}
concurrentQueue.async {
print("Task 2 Con Start")
print("Task 2 Con Finished")
}
}
myConcurrentQueue()
I guess the result should be:
Task 1 Con Start
Task 2 Con Start
Task 1 Con Finished
Task 2 Con Finished
But the result is shown as picture below
As a result, I have 2 problems from the issue above.
- Why does the concurrent queue return a result like this?
- Does
labelin DispatchQueue affect the result?

The dispatched work does not take long enough to experience parallel execution. The first one may run so quickly that it finishes before the second has a chance to start. (And the fact that
printoutput is synchronized, exacerbates this.) Try inserting aThread.sleep(…)(which you’d never do in production code, but is useful for diagnostic purposes) or something time-consuming.For example:
I might suggest including some information to show information about when the output was generated (hence my use of the
ContinuousClockin the above).Anyway, that produces something like:
Note, because these run in parallel, you technically have no assurances regarding which item reaches its respective
printstatements first (thus in this example, task 2 happened to finish a fraction of a millisecond before task 1), but you can see them run in parallel.And, in answer to your question, no, the choice of label does not matter. That is used for diagnostic purposes only.
Also, note that just because you use a concurrent queue does not guarantee that you will necessarily experience parallel execution. It depends upon whether the other cores are busy doing something else, or not. Also, I’d be wary of testing this sort of stuff in playgrounds (if you are) as that can sometimes exhibit execution characteristics that are quite atypical of a real app.
Another way to visualize the parallel execution is to use the “Points of Interest” tool in Instruments as outlined in How to identify key events in Xcode Instruments?
That lets us visualize the concurrent queue’s behavior on a timeline from within Instruments, and you can see they run in parallel. But again, we only see that because I had it do something slow enough such that the first work item likely will not finish before the second work item has a chance to start:
Note, nowadays we would not generally reach for GCD concurrent queues. We would instead use Swift concurrency, and in this case, a “task group”:
For more information, see WWDC 2021 video Meet async/await in Swift. And task groups are introduced at 12:52 in Explore structured concurrency in Swift.
Bottom line, Swift concurrency is beyond the scope of the question, but I wanted to share the modern alternative to concurrent dispatch queues.