同步 dispatch_sync 异步 dispatch_async
串行队列
dispatch_queue_create(“com.yuna.com”, DISPATCH_QUEUE_SERIAL/NULL);
并行队列
dispatch_queue_create(“com.yuna.com”, DISPATCH_QUEUE_CONCURRENT);
主队列:dispatch_get_main_queue()
全局队列:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
全局 + 异步:开启新线程,任务是并发的
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
//队列中添加异步任务
dispatch_async(queue, ^{ });
全局队列 + 同步任务:,没有开启新线程,任务逐个执行
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
//在队列里添加同步任务
dispatch_sync(queue, ^{ });
博主地址 感谢 https://blog.csdn.net/ycf03211230/article/details/79565966
网友评论