Dispatch Queues
About Dispatch Queues

5. Some other key points to remember about dispatch queues include the following:
- Dispatch queues execute their tasks concurrently with respect to other dispatch queues. The serialization of tasks is limited to the tasks in a single dispatch queue.
- The system determines the total number of tasks executing at any one time.
- The system takes queue priority levels into account when choosing which new tasks to start.
- Tasks in a queue must be ready to execute at the time they are added to the queue.
- Private dispatch queues are reference-counted objects. In addition to retaining the queue in your own code, be aware that dispatch sources can also be attached to a queue and also increment its retain count. Thus, you must make sure that all dispatch sources are canceled and all retain calls are balanced with an appropriate release call.
Queue-Related Technologies

Implementing Tasks Using Blocks
1. A block is actually represented by an underlying data structure that resembles an object and is created and managed for you by the compiler. The compiler packages up the code you provide (along with any related data) and encapsulates it in a form that can live in the heap and be passed around your application.
2. One of the key advantages of blocks is their ability to use variables from outside their own lexical scope. For example, a block can read the values of variables defined in the parent scope. Variables accessed by the block are copied to the block data structure on the heap so that the block can access them later. When blocks are added to a dispatch queue, these values must typically be left in a read-only format. However, blocks that are executed synchronously can also use variables that have the __block keyword prepended to return data back to the parent’s calling scope.