dispatch_group_t group =dispatch_group_create();
dispatch_queue_t globalQueue=dispatch_get_global_queue(0,0);
dispatch_group_enter(group);
//模拟多线程耗时操作dispatch_group_async(group, globalQueue, ^{
sleep(3);
NSLog(@"%@---block1结束。。。",[NSThread currentThread]);
dispatch_group_leave(group);
});
NSLog(@"%@---1结束。。。",[NSThread currentThread]);
dispatch_group_enter(group);
//模拟多线程耗时操作dispatch_group_async(group, globalQueue, ^{
sleep(3);
NSLog(@"%@---block2结束。。。",[NSThread currentThread]);
dispatch_group_leave(group);
});
NSLog(@"%@---2结束。。。",[NSThread currentThread]);
dispatch_group_notify(group, dispatch_get_global_queue(0,0), ^{
NSLog(@"%@---全部结束。。。",[NSThread currentThread]);
});
网友评论