1、串行队列
1、DISPATCH_QUEUE_SERIAL
/// 用于创建按先进先出(FIFO)顺序串行调用块的调度队列 #define DISPATCH_QUEUE_SERIAL NULL
2、dispatch_get_main_queue()
/// 绑定到主线程的默认队列。 dispatch_queue_main_t dispatch_get_main_queue(void) { return DISPATCH_GLOBAL_OBJECT(dispatch_queue_main_t, _dispatch_main_q); }
2、并行队列
1、DISPATCH_QUEUE_CONCURRENT
/// 可以并发调用块并支持使用dispatch barrier API提交的障碍块的调度队列。 #define DISPATCH_QUEUE_CONCURRENT \ DISPATCH_GLOBAL_OBJECT(dispatch_queue_attr_t, \ _dispatch_queue_attr_concurrent)
2、dispatch_get_global_queue(queue_priority, 0);
/** 返回一个已知全局并发队列。已知的全局并发队列不能被修改。 * identifier:队列优先级标识 * flags: 默认传入0就好了 */ dispatch_queue_t dispatch_get_global_queue(long identifier, unsigned long flags); /// 全局并发队列由它们的优先级标识,优先级映射到以下几个级别: #define DISPATCH_QUEUE_PRIORITY_HIGH 2 #define DISPATCH_QUEUE_PRIORITY_DEFAULT 0 #define DISPATCH_QUEUE_PRIORITY_LOW (-2) #define DISPATCH_QUEUE_PRIORITY_BACKGROUND INT16_MIN
3、创建Queue
dispatch_queue_create(@”字符串标签”,DISPATCH_QUEUE_CONCURRENT / DISPATCH_QUEUE_SERIAL )
/**创建Queue * label:字符串标签,可以为空。 * attr:队列类型: * 1、传入DISPATCH_QUEUE_SERIAL or a NULL创建的是顺序执行的串行队列; * 2、传入DISPATCH_QUEUE_CONCURRENT创建的是并发队(有点像是global concurrent queues) */ dispatch_queue_t dispatch_queue_create(const char *_Nullable label, dispatch_queue_attr_t _Nullable attr);
示例:
//获取主队列 dispatch_queue_t mainQueue = dispatch_get_main_queue(); //全局并发队列 dispatch_queue_t queue4 = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); //串行队列:DISPATCH_QUEUE_SERIAL|NULL dispatch_queue_t queue3 = dispatch_queue_create("queue3", DISPATCH_QUEUE_SERIAL|NULL); //并行队列:DISPATCH_QUEUE_CONCURRENT dispatch_queue_t queue4 = dispatch_queue_create("queue4", DISPATCH_QUEUE_CONCURRENT)