这个标题其实是有些不对的, 实际要实现的功能是执行完A,B,C 三个任务之后, 再执行D.
第一种方式:
使用dispa_group完成
- (void)orderImplementGCD{
dispatch_queue_t queue = dispatch_get_global_queue(0, 0);
dispatch_group_t group = dispatch_group_create();
dispatch_group_enter(group);
dispatch_async(queue, ^{
NSLog(@"执行第一个任务");
dispatch_group_leave(group);
NSLog(@"*******%@",[NSThread currentThread]);
});
dispatch_group_enter(group);
dispatch_async(queue, ^{
NSLog(@"执行第二个任务");
dispatch_group_leave(group);
NSLog(@"*******%@",[NSThread currentThread]);
});
dispatch_group_enter(group);
dispatch_async(queue, ^{
NSLog(@"执行第三个任务");
dispatch_group_leave(group);
NSLog(@"*******%@",[NSThread currentThread]);
});
dispatch_group_notify(group, queue, ^