Created
May 4, 2018 03:39
-
-
Save zhangkn/193d94df5d31a672313f130bca31f83c to your computer and use it in GitHub Desktop.
GCD的使用小结
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0)queue: dispatch_get_global_queue、dispatch_get_main_queue、dispatch_queue_create | |
1)dispatch:dispatch_after、dispatch_async、dispatch_sync、 | |
dispatch_barrier_async( 场景:在写的过程中不能被读:要等到当前所有并发的block都执行完毕,才会单独执行这个barrier block代码块,等到这个barrier block执行完毕,再继续正常处理其他并发bloc) | |
2)dispatch_group:dispatch_group_t、dispatch_group_async、dispatch_group_wait、dispatch_group_notify、dispatch_group_enter、dispatch_group_leave | |
-- 简单的场景:请求多个接口,再进行View的渲染 | |
3) dispatch信号量(dispatch semaphore): | |
// dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); | |
// dispatch_semaphore_wait(semaphore,dispatch_time(DISPATCH_TIME_NOW, (int64_t)( 16 * NSEC_PER_SEC)));//保证是同步的 | |
dispatch_semaphore_signal(semaphore);//在特定的条件激活信号,往下执行code;有些场景使用递归实现更好 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment