Main thread and main queue: whatâs the difference?
Main thread and main queue: whatâs the difference? êŽë š
Updated for Xcode 15
The main thread is the one that starts our program, and itâs also the one where all our UI work must happen. However, there is also a main queue, and although sometimes we use the terms âmain threadâ and âmain queueâ interchangeably, they arenât quite the same thing.
Itâs a subtle distinction, but it can sometimes matter: although your main queue will always execute on the main thread (and is therefore where youâll be doing your UI work!), itâs also possible that other queues might sometimes run on the main thread â the system is free to move things around in whatever way is most efficient.
So, if youâre on the main queue then youâre definitely on the main thread, but being on the main thread doesnât automatically mean youâre on the main queue â a different queue could temporarily be running on the main thread.
At this point youâre very likely staring at the screen wondering when this would ever be a problem, or perhaps even rereading what I said like itâs a cryptic riddle. Trust me, if you ever hit a problem where the main thread vs main queue matters, youâll be glad you read this!