NSLog(@"start");
//异步并发队列
dispatch_queue_t queue = dispatch_queue_create("current", DISPATCH_QUEUE_CONCURRENT);
dispatch_async(queue, ^{
NSLog(@"%@--1",[NSThread currentThread]);
});
dispatch_async(queue, ^{
NSLog(@"%@--2",[NSThread currentThread]);
});
//栅栏函数
dispatch_barrier_async(queue, ^{
NSLog(@"++++barrier+++++");
});
NSLog(@"11111111");
dispatch_async(queue, ^{
NSLog(@"%@--3",[NSThread currentThread]);
});
dispatch_async(queue, ^{
NSLog(@"%@--4",[NSThread currentThread]);
});
需要用自定义并发队列
dispatch_barrier_sync(queue,void(^block)())会将queue中barrier前面添加的任务block全部执行后,再执行barrier任务的block,再执行barrier后面添加的任务block.
dispatch_barrier_async(queue,void(^block)())会将queue中barrier前面添加的任务block只添加不执行,继续添加barrier的block,再添加barrier后面的block,同时不影响主线程(或者操作添加任务的线程)中代码的执行!
网友评论