开发中经常遇到这样的情况,需要两个线程执行完毕再操作。直接上示例代码
dispatch_group_t group = dispatch_group_create();
dispatch_group_async(group, dispatch_get_global_queue(0, 0), ^{
[NSThread sleepForTimeInterval:5];
NSLog(@"线程一");
});
dispatch_group_async(group, dispatch_get_global_queue(0, 0), ^{
[NSThread sleepForTimeInterval:10];
NSLog(@"线程二");
});
dispatch_group_notify(group, dispatch_get_global_queue(0, 0), ^{
NSLog(@"线程一二都执行完毕");
});