1.dispatch_barrier_async 不阻塞队列但阻塞任务 实现拦截 (异步特性体现在将任务插入队列的过程,而等待特性体现在任务执行的过程)
2.dispatch_barrier_sync 阻塞队列也阻塞任务 实现拦截
// 串行队列同步栅栏
- (void)serailQueueSyncRun {
dispatch_queue_t queue = dispatch_queue_create("com.queue.s", DISPATCH_QUEUE_SERIAL);
dispatch_async(queue, ^{
NSLog(@"yxg-- async- a");
});
dispatch_async(queue, ^{
NSLog(@"yxg-- async- b");
});
dispatch_async(queue, ^{
NSLog(@"yxg-- async- c");
});
// 阻塞队列也阻塞任务 实现拦截
dispatch_barrier_sync(queue, ^{
NSLog(@"yxg-- barrier_sync-d");
});
NSLog(@"串行队列同步栅栏函数");
dispatch_async(queue, ^{
NSLog(@"yxg-- async- e");
});
dispatch_async(queue, ^{
NSLog(@"yxg-- async- f");
});
dispatch_async(queue, ^{
NSLog(@"yxg-- async- g");
});
}
WeChatWorkScreenshot_0afc5b9f-7cc0-4c73-861b-da1522108241.png
// 串行队列异步栅栏
- (void)serailQueueAsyncRun {
dispatch_queue_t queue = dispatch_queue_create("com.queue.s", DISPATCH_QUEUE_SERIAL);
dispatch_async(queue, ^{
NSLog(@"yxg-- async- a");
});
dispatch_async(queue, ^{
NSLog(@"yxg-- async- b");
});
dispatch_async(queue, ^{
NSLog(@"yxg-- async- c");
});
// 不阻塞队列但阻塞任务 实现拦截
dispatch_barrier_async(queue, ^{
NSLog(@"yxg-- barrier_async- d");
});
NSLog(@"串行队列异步栅栏函数");
dispatch_async(queue, ^{
NSLog(@"yxg-- async- e");
});
dispatch_async(queue, ^{
NSLog(@"yxg-- async- f");
});
dispatch_async(queue, ^{
NSLog(@"yxg-- async- g");
});
}
WeChatWorkScreenshot_10e5bf43-abd8-4e87-8456-fde1bcec7534.png
// 并行队列异步栅栏
- (void)asyncRun {
dispatch_queue_t queue = dispatch_queue_create("com.queue.c", DISPATCH_QUEUE_CONCURRENT);
dispatch_async(queue, ^{
NSLog(@"yxg-- async- a");
});
dispatch_async(queue, ^{
NSLog(@"yxg-- async- b");
});
dispatch_async(queue, ^{
NSLog(@"yxg-- async- c");
});
// 不阻塞队列但阻塞任务 实现拦截
dispatch_barrier_async(queue, ^{
NSLog(@"yxg-- barrier_async- d");
});
NSLog(@"并行队列异步栅栏函数");
dispatch_async(queue, ^{
NSLog(@"yxg-- async- e");
});
dispatch_async(queue, ^{
NSLog(@"yxg-- async- f");
});
dispatch_async(queue, ^{
NSLog(@"yxg-- async- g");
});
}
WeChatWorkScreenshot_c4c77daf-0487-4c67-a8c0-afb9ea6097fb.png
// 并行队列同步栅栏
- (void)syncRun {
dispatch_queue_t queue = dispatch_queue_create("com.queue.c", DISPATCH_QUEUE_CONCURRENT);
dispatch_async(queue, ^{
NSLog(@"yxg-- async- a");
});
dispatch_async(queue, ^{
NSLog(@"yxg-- async- b");
});
dispatch_async(queue, ^{
NSLog(@"yxg-- async- c");
});
// 阻塞队列也阻塞任务 实现拦截
dispatch_barrier_sync(queue, ^{
NSLog(@"yxg-- barrier_sync-d");
});
NSLog(@"并行队列同步栅栏函数");
dispatch_async(queue, ^{
NSLog(@"yxg-- async- e");
});
dispatch_async(queue, ^{
NSLog(@"yxg-- async- f");
});
dispatch_async(queue, ^{
NSLog(@"yxg-- async- g");
});
}
WeChatWorkScreenshot_2a551702-7338-42c1-9692-f6cdc7fdc1e4.png