We live in a multicore computing world. Multicore processors are found in everything, from our laptops and mobile phones to our watches. With these multiple cores comes the ability to work in parallel. These concurrent streams of work are known as threads, and programming in a multithreaded way enables your code to make the best use of the processor's cores. Deciding how and when to create new threads and manage the available resources are complex tasks, so Apple has built a framework to do the hard work for us. It is called Grand Central Dispatch.
Grand Central Dispatch (GCD) handles the thread maintenance and monitors the available resources while providing a simple, queue-based interface for getting concurrent work done. With the open-sourcing of Swift, Apple also open-sourced GCD in the form of libdispatch, since Swift does not yet have built-in concurrency features.
In this recipe, we will explore some of the features of libdispatch, also...