Thread and Grand Central Dispatch(GCD) in Swift
A thread is the smallest unit of execution within a process.
Multithreading allows multiple tasks to be executed at the same time.
What Grand Central Dispatch in swift?
GCD shifts the responsibility for managing threads and the execuation from applications to the operating system. GCD is apple popular and easy to use way of handiling concurrency.
How its work?
GCD uses queues of closures to perform tasks submitted to the system. From apple documentation Queues or dispatchQueues are defines as object that manages the execuation of task searially or concurrently.
GCD provides three Queues :
- Main Queue : Serial
- Global Queue: Concurrent
- Custom Queue : serial / concurrent
When we create an application there is a Main thread created too. it’s association with the application. Application have only one main thread.
Main Queue run on the main thread. if for any reason main thread is block then application will be crashed.
The main queue in GCD is a serial queue, not a concurrent queue. The main queue processes tasks in a serial manner, meaning that tasks are executed one at a time, in the…