In: Computer Science
Various libraries, like pThread.h (and its associated library) in C, give languages exposure to the underlying system’s threading system. How does working with Grand Central Dispatch differ from other threading systems you have used (if you have never used threading, read up on Java threading for a comparison)? Be sure to talk about the activities that take place on the main thread versus those that take place on the background threads.
Grand Central Dispatch(GCD) and other threading systems are both designed to encapsulate units of work and send them for execution. One of the most used threading system is NSOperation , it is an objective-C API and it brings with it some overhead.
After the introduction of GCD Apple refactored NSOperation to work on top of GCD.
GCD is low level-C API that directly interacts with Unix level of the system.
In case you are using NSOperation then you are implicitly using GCD.
GCD is ideal if you have to send off a block of code to a serial or a concurrent queue. Benifit of using Grand Central Dispatch is that you can keep all the related codes together.
In GCD the kernel threads/ background threads are preemptive and the user threads/main threads are cooperative.User space threads are multitasking threads and can give better throughput but the disadvantage is that it can kill the responsiveness of the entire system. GCD can solve this by spawning some extra kernel threads if the user space threads are not completing blocks fast enough.