GCD提供了并管理着若干FIFO队列(queues),可以通过block的形式向这些FIFO序列提交任务。GCD同时维护着一个线程池,所有的任务在线程池的线程运行。
系统在启动后会创建一个特殊的队列,叫做主队列(main queue)。主队列中的任务在主线程中顺序执行。(也就是说主线程上的不一定是主队列)
Attempting to synchronously execute a work item on the main queue results in dead-lock.
通过指定的quality of service (QoS)获取。
A dispatch semaphore is an efficient implementation of a traditional counting semaphore. Dispatch semaphores call down to the kernel only when the calling thread needs to be blocked. If the calling semaphore does not need to block, no kernel call is made.
dispatch semaphore比传统的信号量更有效率。
A dispatch barrier allows you to create a synchronization point within a concurrent dispatch queue. When it encounters a barrier, a concurrent queue delays the execution of the barrier block (or any further blocks) until all blocks submitted before the barrier finish executing. At that point, the barrier block executes by itself. Upon completion, the queue resumes its normal execution behavior
提供了一种同步机制,前提是dispatch queue是并行的,且不是global concurrent dispatch queue。
执行顺序会是这样子:
之前的block->这个block->之后的block
细说GCD(Grand Central Dispatch)如何用