When execute GCD's async task, Is executing like Async/Await or not?

These days, I am studying about concurrency. GCD and Async/Await in Swift 5.5 etc...

Using GCD, tasks are enqueued in the GCD's queue through the sync() and async() functions. And specific queue execute tasks through threads.

I have a question here.

Async/await tasks are known to execute parts of the task while repeating suspend and resume according to the status of system resources if there is an await keyword inside the task.

When a GCD's specific task is executed through a specific thread, does it run to the end once started? Or is task's closure executed while repeating suspend resume like async/await?

The closure argument to GCD routines like DispatchQueue.async(…) is a standard function, not as async one. Such functions can’t suspend in the Swift concurrency sense. So, the answer to this question:

When a GCD's specific task is executed through a specific thread, does
it run to the end once started?

is “Yes.”

However, I suspect you’ll have a bunch of follow-up questions and my advice on that front is to watch WWDC 2021 Session 10254 Swift concurrency: Behind the scenes, which is a great explanation of how the Swift concurrency runtime works.

Share and Enjoy

Quinn “The Eskimo!” @ DTS @ Apple

3 Likes

Thank you so much for letting me know. I'll have to watch the video right away :]