作用:只有当栅栏函数执行完毕后才能执行后面的函数
需求:使用栅栏函数规定线程执行顺序
注意点:栅栏函数不能使用全局并发队列
使用示例
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent*)event
{
dispatch_queue_t queue = dispatch_queue_create("download", DISPATCH_QUEUE_CONCURRENT);
//1.异步函数
dispatch_async(queue, ^{
for(NSIntegeri =0; i <5; i++){
NSLog(@"download1 -- %zd -- %@",i,[NSThread currentThread]);
}
});
dispatch_async(queue, ^{
for(NSIntegeri =0; i <5; i++){
NSLog(@"download2 -- %zd -- %@",i,[NSThread currentThread]);
}
});
dispatch_barrier_async(queue, ^{
NSLog(@"+++++++++++++++");
});
dispatch_async(queue, ^{
for(NSIntegeri =0; i <5; i++){
NSLog(@"download3 -- %zd -- %@",i,[NSThread currentThread]);
}
});
dispatch_barrier_async(queue, ^{
NSLog(@"+++++++++++++++");
});
dispatch_async(queue, ^{
for(NSIntegeri =0; i <5; i++){
NSLog(@"download4 -- %zd -- %@",i,[NSThread currentThread]);
}
});
}