#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
[self barrier];
}
- (void)barrier {
dispatch_queue_t queue = dispatch_queue_create("Test", DISPATCH_QUEUE_CONCURRENT);
dispatch_async(queue, ^{
NSLog(@"1-----%@",[NSThread currentThread]);
});
dispatch_barrier_async(queue, ^{
NSLog(@"1+++++++++++");
});
dispatch_async(queue, ^{
NSLog(@"2-----%@",[NSThread currentThread]);
});
dispatch_barrier_async(queue, ^{
NSLog(@"2+++++++++++");
});
dispatch_async(queue, ^{
NSLog(@"3-----%@",[NSThread currentThread]);
});
dispatch_barrier_async(queue, ^{
NSLog(@"3+++++++++++");
});
dispatch_async(queue, ^{
NSLog(@"4-----%@",[NSThread currentThread]);
});
dispatch_barrier_async(queue, ^{
NSLog(@"4+++++++++++");
});
dispatch_async(queue, ^{
NSLog(@"5-----%@",[NSThread currentThread]);
});
dispatch_async(queue, ^{
NSLog(@"6-----%@",[NSThread currentThread]);
});
dispatch_async(queue, ^{
NSLog(@"7-----%@",[NSThread currentThread]);
});
dispatch_async(queue, ^{
NSLog(@"8-----%@",[NSThread currentThread]);
});
}
@end