dispatch,dispatcher
GCD提供了並管理著若干FIFO隊列(queues),可以通過block的形式向這些FIFO序列提交任務。GCD同時維護著一個線程池,所有的任務線上程池的線程運行。
系統提供的隊列main queue
系統在啟動後會建立一個特殊的隊列,叫做主隊列(main queue)。主隊列中的任務在主線程中順序執行。(也就是說主線程上的不一定是主隊列)
Attempting to synchronously execute a work item on the main queue results in dead-lock.
global concurrent dispatch queues
通過指定的quality of service (QoS)擷取。
Dispatch Semaphores
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比傳統的訊號量更有效率。
Dispatch Barriers
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)如何用