GCD系列是阅读官方文件和在实践中总结的一些常见的GCD用法,基本涉及全部的GCD内容形成的集合文章,文章重点在与精简和全面覆盖。
学习本集合你可以了解:
1. GCD是如何做到多线程调度的
2. 对比其他iOS的多线程方案,GCD的优势和劣势
3. 如何使用GCD相关的API我将在后续不断补充详细内容和实际案例, 欢迎关注,提问和讨论
03-dispatch_after/dispatch_time-延迟调度和操作
04-dispatch_barrier_sync/async-线程阻塞
07-dispatch_semaphore-信号量/数据同步
11-GCD死锁
[TOC]
dispatch_group是干什么的?
在处理并发操作的时候,如果是几个block同时并发,我们无法知道最后执行完毕的时候是在哪一个Block中,那么就无法知道在哪一个位置写上结束时的代码?
dispatch_group_async 和 dispatch_group_notify可以实现这个功能。
dispatch_group
dispatch_group将提交到这个group的blocks关联起来,group需要等到所有的Block执行完成之后才能释放内存。
Creates new group with which blocks may be associated.
* @discussion
* This function creates a new group with which blocks may be associated.
* The dispatch group may be used to wait for the completion of the blocks it
* references. The group object memory is freed with dispatch_release().
dispatch_group_t dispatch_group_create(void);
dispatch_group_async
Submits a block to a dispatch queue and associates the block with the given dispatch group.
*
* @discussion
* Submits a block to a dispatch queue and associates the block