码迷,mamicode.com
首页 > 其他好文 > 详细

dispatch

时间:2016-09-18 23:34:31      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:

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

dispatch

标签:

原文地址:http://www.cnblogs.com/huahuahu/p/dispatch.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!