美文网首页
关于gcd调度组的简单使用

关于gcd调度组的简单使用

作者: 不泯iOS | 来源:发表于2020-02-21 15:05 被阅读0次

    两种写法:

    /*
    调度组最重要的任务:监听一组任务的完成
     */
    -(void)group1{
        //创建调度组
        dispatch_group_t group = dispatch_group_create();
        //创建队列
        dispatch_queue_t t = dispatch_get_global_queue(0, 0);
        //调度组监听队列调度任务
        dispatch_group_async(group, t, ^{
            NSLog(@"download A %@",[NSThread currentThread]);
        });
        dispatch_group_async(group, t, ^{
            NSLog(@"download b %@",[NSThread currentThread]);
        });
        dispatch_group_notify(group, t, ^{
            NSLog(@"come here");
        });
    }
    
    -(void)group2{
        //1.创建调度组
        dispatch_group_t group = dispatch_group_create();
        //2.创建队列
        dispatch_queue_t t = dispatch_get_global_queue(0, 0);
        //3.调度组
        //1>入组
        dispatch_group_enter(group);
        dispatch_group_async(group, t, ^{
            NSLog(@"download A %@",[NSThread currentThread]);
            //2>出组
            dispatch_group_leave(group);
        });
        //1>入组
        dispatch_group_enter(group);
        dispatch_group_async(group, t, ^{
            NSLog(@"download A %@",[NSThread currentThread]);
            //2>出组
            dispatch_group_leave(group);
        });
        dispatch_group_notify(group, t, ^{
            NSLog(@"come here");
        });
    
    }
    

    相关文章

      网友评论

          本文标题:关于gcd调度组的简单使用

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