dispatch_group示例

2018-04-16  本文已影响8人  迷路的安然和无恙

应用场景

- (void)viewDidLoad {
    [super viewDidLoad];
    
//    dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
    
    dispatch_group_t group = dispatch_group_create();
    
    dispatch_queue_t concurrentQueue = dispatch_queue_create("custemer_queue", DISPATCH_QUEUE_CONCURRENT);
    
    dispatch_group_async(group, concurrentQueue, ^{
        NSLog(@"A");
    });
    dispatch_group_async(group, concurrentQueue, ^{
        NSLog(@"B");
    });
    dispatch_group_async(group, concurrentQueue, ^{
        NSLog(@"C");
    });
    dispatch_group_async(group, concurrentQueue, ^{
        NSLog(@"D");
    });
    
    dispatch_group_notify(group, concurrentQueue, ^{
        NSLog(@"都执行完了");
    });
    dispatch_group_wait(group, DISPATCH_TIME_FOREVER);
    
    NSLog(@"finish");
}

image.png
上一篇下一篇

猜你喜欢

热点阅读