- (void)testAsync3{
//注意这个地方是全局队列,dispatch_get_global_queue
dispatch_queue_t queue = dispatch_get_global_queue(0, 0);
for (int i = 0; i<100; i++) {
dispatch_async(queue, ^{
NSLog(@"%@",@(i));
});
}
dispatch_barrier_async(queue, ^{
NSLog(@"a");
});
NSLog(@"b");
for (int i = 0; i< 100; i++) {
dispatch_async(queue, ^{
NSLog(@"%@",@(i));
});
}
}
- (void)testAsync2{
dispatch_queue_t queue = dispatch_queue_create("queue", DISPATCH_QUEUE_CONCURRENT);
NSMutableArray *a = [NSMutableArray array];
for (int i = 0; i< 100; i++) {
dispatch_async(queue, ^{
[a addObject:@(i)];
});
}
NSLog(@"%@",a);
}
网友评论