首页 > 代码库 > dispatch_barrier_async
dispatch_barrier_async
代码:
dispatch_queue_t queue = dispatch_queue_create("queue", DISPATCH_QUEUE_CONCURRENT); dispatch_async(queue, ^{ NSLog(@"Before Barrier Block - 1"); }); dispatch_async(queue, ^{ NSLog(@"Before Barrier Block - 2"); }); dispatch_async(queue, ^{ NSLog(@"Before Barrier Block - 3"); }); dispatch_async(queue, ^{ NSLog(@"Before Barrier Block - 4"); }); dispatch_async(queue, ^{ NSLog(@"Before Barrier Block - 5"); }); dispatch_barrier_async(queue, ^{ NSLog(@"Barrier Block"); }); dispatch_async(queue, ^{ NSLog(@"After Barrier Block - 1"); }); dispatch_async(queue, ^{ NSLog(@"After Barrier Block - 2"); }); dispatch_async(queue, ^{ NSLog(@"After Barrier Block - 3"); }); dispatch_async(queue, ^{ NSLog(@"After Barrier Block - 4"); }); dispatch_async(queue, ^{ NSLog(@"After Barrier Block - 5"); });
可能的输出:
Before Barrier Block - 1 Before Barrier Block - 2 Before Barrier Block - 3 Before Barrier Block - 5 Before Barrier Block - 4 Barrier Block After Barrier Block - 1 After Barrier Block - 3 After Barrier Block - 2 After Barrier Block - 5 After Barrier Block - 4
备注:
dispatch_barrier_async用于在同一个并发队列中,同步多个并发操作
dispatch_barrier_async
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。