美文网首页
dispatch_apply and dispatch_b

dispatch_apply and dispatch_b

作者: Etoaer | 来源:发表于2019-03-06 17:53 被阅读0次

 //自动开启线程数目控制,最优不会过多崩溃

    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");

相关文章

网友评论

      本文标题:dispatch_apply and dispatch_b

      本文链接:https://www.haomeiwen.com/subject/nvyxpqtx.html