研究了下dispatch_barrier_async() 顺便把GCD的常用函数都看下.
dispatch_queue_t dispatch_queue_create
文档解释:Creates a new dispatch queue to which blocks can be submitted.
创建一个新的,可以让提交代码块的分发队列.
Parameters:
label
A string label to attach to the queue to uniquely identify it in debugging tools such as Instruments, sample, stackshots, and crash reports. Because applications, libraries, and frameworks can all create their own dispatch queues, a reverse-DNS naming style (com.example.myqueue) is recommended. This parameter is optional and can be NULL.
用于deug时候 绑定在队列上的一个独特的字符串标签,区别系统或者其他框架创建的队列.这个参数可以为空.
attr
In OS X v10.7 and later or iOS 4.3 and later, specify DISPATCH_QUEUE_SERIAL (or NULL) to create a serial queue or specify DISPATCH_QUEUE_CONCURRENT to create a concurrent queue. In earlier versions, you must specify NULL for this parameter.
这个参数 不读不知道,一读吓一跳.
指定 DISPATCH_QUEUE_SERIAL 或者是NULL的时候,创建的队列是串行队列.
指定DISPATCH_QUEUE_CONCURRENT 创建的是并发队列.
在更早的版本中这个参数只能指定NULL
讨论:
Blocks submitted to a serial queue are executed one at a time in FIFO order. Note, however, that blocks submitted to independent queues may be executed concurrently with respect to each other. Blocks submitted to a concurrent queue are dequeued in FIFO order but may run concurrently if resources are available to do so.
代码块被提交到串行队列的执行顺序是一个接着一个的执行,按照先进先出的原则.
然而需要注意的是:代码块被提交到一个独立的队列,可能会彼此并发的执行,
代码块提交到一个并发的队列,也是按照先进先出的顺序,进行出队.但是如果资源允许的话,可能是并发执行.
When your application no longer needs the dispatch queue, it should release it with the dispatch_release function. Any pending blocks submitted to a queue hold a reference to that queue, so the queue is not deallocated until all pending blocks have completed.
当你的程序不再需要这个队列的时候,需要和私用dispathc_release(),去释放这个队列.
任何提交到队列的还没有执行block代码块,都会持有这个队列的引用.所以这个队列并不会被销毁,直到所有的block被执行完毕.