美文网首页
dispatch_group_notify

dispatch_group_notify

作者: 雪丹妮_66865 | 来源:发表于2019-09-25 15:28 被阅读0次

dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_group_t group = dispatch_group_create();
dispatch_group_enter(group);
dispatch_group_async(group, queue, ^{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
dispatch_group_leave(group);
NSLog(@"任务aaaaaa");
});
});
dispatch_group_enter(group);
dispatch_group_async(group, queue, ^{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
dispatch_group_leave(group);
NSLog(@"任务bbbbbb");
});
});
dispatch_group_notify(group, queue, ^{
NSLog(@"notify任务任务问去任务e任务");
});
dispatch_group_async(group, queue, ^{
NSLog(@"任务66666666");
});
NSLog(@"我就是想看看会不会阻塞前面的线程");

//创建信号量
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
//创建全局并行
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_group_t group = dispatch_group_create();
dispatch_group_async(group, queue, ^{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
dispatch_semaphore_signal(semaphore);
NSLog(@"任务aaaaaa");
});
});

dispatch_group_async(group, queue, ^{
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        dispatch_semaphore_signal(semaphore);
        NSLog(@"任务bbbbbbbbb");
    });
});
dispatch_group_notify(group, queue, ^{
    dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
    dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
    NSLog(@"notify任务任务问去任务e任务");
});
NSLog(@"我就是想看看会不会阻塞前面的线程");

相关文章

网友评论

      本文标题:dispatch_group_notify

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