美文网首页
GCD 组队列

GCD 组队列

作者: 沬日十七 | 来源:发表于2019-07-31 09:12 被阅读0次

dispatch_group_t group =dispatch_group_create();

    dispatch_queue_t globalQueue=dispatch_get_global_queue(0,0);

        dispatch_group_enter(group);

    //模拟多线程耗时操作dispatch_group_async(group, globalQueue, ^{

        sleep(3);

        NSLog(@"%@---block1结束。。。",[NSThread currentThread]);

        dispatch_group_leave(group);

    });

    NSLog(@"%@---1结束。。。",[NSThread currentThread]);

    dispatch_group_enter(group);

    //模拟多线程耗时操作dispatch_group_async(group, globalQueue, ^{

        sleep(3);

        NSLog(@"%@---block2结束。。。",[NSThread currentThread]);

        dispatch_group_leave(group);

    });

    NSLog(@"%@---2结束。。。",[NSThread currentThread]);

    dispatch_group_notify(group, dispatch_get_global_queue(0,0), ^{

        NSLog(@"%@---全部结束。。。",[NSThread currentThread]);

    });

相关文章

网友评论

      本文标题:GCD 组队列

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