码迷,mamicode.com
首页 > 移动开发 > 详细

dispatch_apply&dispatch_suspend&dispatch_resume使用

时间:2015-01-31 19:27:58      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:

第一、dispatch_apply 是同步函数,会阻塞当前线程直到所有循环迭代执行完成。当提交到并发queue时,循环迭代的执行顺序是不确定的
示例:
        dispatch_queue_t queue=dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
        dispatch_apply(10, queue, ^(size_t index) {
            NSLog(@"%zu",index);
        });
执行结果:
8 1 2 4 5 3 9 0 7 6
因为dispatch_apply会等待处理执行结束,因此推荐在dispatch_asyn函数中执行dispatch_apply


第二、dispatch_suspend挂起指定的dispatch_queue


第三、dispatch_resume恢复指定的dispatch_queue


dispatch_apply&dispatch_suspend&dispatch_resume使用

标签:

原文地址:http://blog.csdn.net/richard_rufeng/article/details/43342395

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!