GCD-dispatch_barrier_async

提交一个障碍任务,这个任务之前的任务安规则正常执行,等到它之前的任务全部执行完毕之后,才开始执行这个障碍任务。
但是这个障碍任务本身不管是否在并行队列里面,这个障碍任务本身是单独执行的。
障碍任务执行完成后,再按正常规则执行后续的任务
示例:

- (IBAction)GCD_dispatch_barrier_async_buttonAction:(UIButton *)sender {
    //创建一个并行执行队列
    dispatch_queue_t queue = dispatch_queue_create("queueIdentifier", DISPATCH_QUEUE_CONCURRENT);
    //以下两个任务执行顺序不定,因为它们是并行任务
    dispatch_async(queue, ^{
        NSLog(@"&thread:%@-------",[NSThread currentThread]);
    });
    dispatch_async(queue, ^{
        NSLog(@"&thread:%@-------",[NSThread currentThread]);
    });

    //将队列中已添加的任务执行完成后,单独执行下面的任务,不会并行执行
    dispatch_barrier_async(queue, ^{
        NSLog(@"&thread:%@-------",[NSThread currentThread]);
    });

    //上面的任务执行完成后继续正常并行执行任务
    dispatch_async(queue, ^{
        NSLog(@"&thread:%@-------",[NSThread currentThread]);
    });

    dispatch_async(queue, ^{
        NSLog(@"&thread:%@-------",[NSThread currentThread]);
    });

}

输出如下:

@thread:{number = 3, name = (null)}——–
#thread:{number = 3, name = (null)}——-
$barrier:thread:{number = 3, name = (null)}——-
^thread:{number = 3, name = (null)}——-
&thread:{number = 3, name = (null)}——-

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值