GCD调度组

1、第一种方式

- (void)group1 {
    dispatch_group_t group = dispatch_group_create();
    
    dispatch_queue_t q = dispatch_get_global_queue(0, 0);
    
    dispatch_group_enter(group);
    dispatch_async(q, ^{
        NSLog(@"print A: ");
        dispatch_group_leave(group);
    });
  
    dispatch_group_enter(group);
    dispatch_async(q, ^{
        NSLog(@"print B:");
        [NSThread sleepForTimeInterval:1.0];
        dispatch_group_leave(group);
    });
    
    dispatch_group_notify(group, dispatch_get_main_queue(), ^{
        NSLog(@"print C:");
    });
    
}

2、第二种方式

- (void)group2 {
    dispatch_group_t group = dispatch_group_create();
    
    dispatch_queue_t q = dispatch_get_global_queue(0, 0);
    
    dispatch_group_async(group, q, ^{
        NSLog(@"print A: ");
    });
    
    dispatch_group_async(group, q, ^{
        NSLog(@"print B:");
        [NSThread sleepForTimeInterval:1.0];
    });
    
    dispatch_group_notify(group, dispatch_get_main_queue(), ^{
        NSLog(@"print C: ");
    });
}

你可能感兴趣的:(GCD调度组)