Member-only story
The Complete Guide to Concurrency and Multithreading in iOS
Main thread vs. background thread. Async/await and Actor. GCD vs. OperationQueue. Group dispatch, how to empower background thread, and more
Published in
11 min readFeb 15, 2022
Introduction
In this article, we will learn the following:
TABLE OF CONTENTSWhat Is Multithreading
Serial Queue vs. Concurrent Queue
Parallelism
Concurrency
Basics of Multithreading
Main Thread (UI Thread) vs. Background Thread (Global Thread)
GCD (Grand Central Dispatch)
DispatchGroup
DispatchSemaphore
DispatchWorkItem
Dispatch Barrier
AsyncAfter
(NS)Operation and (NS)OperationQueue
DispatchSource (How To Handle Files and Folders)
Deadlock (Issue What To Avoid)
Main Thread Checker (How To Detect Thread Issues)
Threads in Xcode (How To Debug Threads)
Async / Await / Actor Is iOS13+
I know there are lots of topics. If something is already familiar to you, skip it and read the unknown parts. There are tricks and tips.
Multithreading in Real-World Examples
Imagine you have a restaurant. The waiter is gathering the orders. The kitchen is preparing the food, the bartender is making the coffee and the cocktails.