dispatch_group_notify多线程同步输出

dispatch_group_t group = dispatch_group_create();

    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);

dispatch_group_enter(group);

NSLog(@"111");

dispatch_group_leave(group);

dispatch_group_enter(group);

NSLog(@"222");

dispatch_group_leave(group);

dispatch_group_enter(group);

NSLog(@"333");

dispatch_group_leave(group);

dispatch_group_notify(group, queue, ^{

        NSLog(@"全部输出完成!");

    });

NSLog(@"444");

输出结果:444   111   222  333   全部输出完成!

你可能感兴趣的:(dispatch_group_notify多线程同步输出)