//自动开启线程数目控制,最优不会过多崩溃
dispatch_apply(100, dispatch_get_global_queue(0, 0), ^(size_t index) {
NSLog(@"%ld--%@", index,[NSThread currentThread]);
});
dispatch_barrier_async 不会阻塞当前线程,等队列中任务都运行完在运行自己,比自己后加入的等自己运行完才能运行。
dispatch_barrier_sync 会阻塞当前线程一起等待,知道barr内运行完。
dispatch_queue_t queue = dispatch_queue_create("conQueue", DISPATCH_QUEUE_CONCURRENT);
dispatch_async(queue, ^{
[selfdownLoad];
NSLog(@"1111Finish,%@",[NSThread currentThread]);
});
dispatch_async(queue, ^{
[selfdownLoad];
NSLog(@"2222Finish,%@",[NSThread currentThread]);
});
dispatch_barrier_sync(queue, ^{
[selfdownLoad];
NSLog(@"BarrierFinish,%@",[NSThread currentThread]);
});
dispatch_async(queue, ^{
NSLog(@"3333Finish,%@",[NSThread currentThread]);
});
NSLog(@"End");
网友评论