dispatch_group_t group = dispatch_group_create();
dispatch_group_enter(group);
dispatch_group_async(group, dispatch_get_global_queue(0, 0), ^{
sleep(5);
NSLog(@"-------");
dispatch_group_leave(group);
});
dispatch_group_enter(group);
NSLog(@"222222");
dispatch_group_async(group, dispatch_get_global_queue(0, 0), ^{
sleep(5);
NSLog(@"=======");
dispatch_group_leave(group);
});
NSLog(@"33333333");
dispatch_group_notify(group, dispatch_get_main_queue(), ^{
NSLog(@"完成了额");
});
NSLog(@"*******");
只有两个线程中的dispatch_group_leave(group);都执行了才会执行dispatch_group_notify中的block。也就是说dispatch_group_notify中block中的什么时候执行取决于dispatch_group_leave这个函数的执行情况
网友评论