?//自動(dòng)開啟線程數(shù)目控制,最優(yōu)不會(huì)過多崩潰
? ? dispatch_apply(100, dispatch_get_global_queue(0, 0), ^(size_t index) {
? ? ? ? NSLog(@"%ld--%@", index,[NSThread currentThread]);
? ? });
dispatch_barrier_async ?不會(huì)阻塞當(dāng)前線程,等隊(duì)列中任務(wù)都運(yùn)行完在運(yùn)行自己疚颊,比自己后加入的等自己運(yùn)行完才能運(yùn)行次屠。
dispatch_barrier_sync 會(huì)阻塞當(dāng)前線程一起等待,知道barr內(nèi)運(yùn)行完蜗巧。
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");