Skip to content

Instantly share code, notes, and snippets.

@cokecoffe
Last active December 11, 2015 11:18
Show Gist options
  • Select an option

  • Save cokecoffe/4592912 to your computer and use it in GitHub Desktop.

Select an option

Save cokecoffe/4592912 to your computer and use it in GitHub Desktop.
GCD
//创建一个下载队列
dispatch_queue_t downloadQueue = dispatch_queue_create("flickr downloader", NULL);
dispatch_async(downloadQueue, ^{
//在这里做一些需要资源的任务
//分发两个行队列,分别执行do_first_work,do_second_work
dispatch_group_t group = dispatch_group_create();
dispatch_group_async(group,dispatch_get_global_queue(0,0),^{
do_frist_work();
}
dispatch_group_async(group,dispatch_get_global_queue(0,0),^{
do_second_work();
}
//指定group全部完成的时候调用的block
dispatch_group_notify(group,dispatch_get_global_queue(0,0),^{
dispatch_async(dispatch_get_main_queue(), ^{
//返回主线程,更新UI
});
}
});
dispatch_release(downloadQueue);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment