dispatch,dispatcher

來源:互聯網
上載者:User

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)如何用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.