GCD Overview
1. GCD is part of libSystem.dylib
2. Available to all Apps.
- #include <dispatch/dispatch.h>
3. GCD API has block-based and function-based variants
- Focus today on block-based API
Introduction to GCD recap
1. Blocks
- dispatch_async()
2. Queues
- Lightweight list of blocks
- Enqueue/dequeue is FIFO
3. dispatch_get_main_queue()
- Main thread/main runloop
4. dispatch_queue_create()
- Automatic helper thread
GCD Advantages
1. Efficiency - More CPU cycles available for your code
2. Better metaphors
- Blocks are easy to use
- Queues are inherently producer/consumer
3. Systemwide perspective
- Only the OS can balance unrelated subsystems
Compatibility
1. Existing threading and synchronization primitives are 100% compatible
2. GCD threads are wrapped POSIX threads
- Do not cancel, exit, kill, join, or detach GCD threads
3. GCD reuses threads