With the introduction of multicore devices such as the iPad 2 and the quad-core Mac-
Book Pro, writing multithreaded apps that take advantage of multiple cores on a device
has become one of the biggest headaches for developers. Take, for instance, the introduction
of iPad 2. On the launch day, only a few applications, basically those released
by Apple, were able to take advantage of its multiple cores. Applications like Safari
performed very well on the iPad 2 compared to the original iPad, but some third-party
browsers did not perform as well as Safari. The reason behind this is that Apple has
utilized Grand Central Dispatch (GCD) in Safari’s code base. GCD is a low-level C API
that allows developers to write multithreaded applications without the need to manage
threads at all. All developers have to do is define tasks and leave the rest to GCD.
The trend in the industry is mobility. Mobile devices, whether they are as compact as
an iPhone or as strong and full-fledged as an Apple MacBook Pro, have many fewer
resources than computers such as the Mac Pro, because all the hardware has to be
placed inside the small devices’ compact bodies. Because of this, it is very important to
write applications that work smoothly on mobile devices such as the iPhone. We are
not that far away from having quad-core or 8-core smartphones. Once we have 8 cores
in the CPU, an app executed on only one of the cores will run tremendously more
slowly than an app that has been optimized with a technology such as GCD, which
allows the code to be scheduled on multiple cores without the programmer having to
manage this synchronization.
Apple is pushing developers away from using threads and is slowly starting to integrate
GCD into its various frameworks. For instance, prior to the introduction of GCD in
iOS, operations and operation queues used threads. With the introduction of GCD,
Apple completely changed the implementation of operations and operation queues by
using GCD instead of threads.
This book is written for those of you who want to do what Apple suggests and what
seems like the bright future for software development: migrating away from threads
and allowing the operating system to take care of threads for you, by replacing thread
programming with GCD.