iOS之线程组

并行队列

创建线程组队列
dispatch_group_t group = dispatch_group_create();

进入线程队列
dispatch_group_enter(group);
离开线程队列
dispatch_group_leave(group);
线程队列监听通知 ,返回主线程更新UI
dispatch_group_notify(group, dispatch_get_main_queue(), ^{}

串行并列,并行并列

一个串行队列
dispatch_queue_t queue = dispatch_queue_create("queue.group", NULL);
或者一个并行队列
dispatch_queue_t queue = dispatch_queue_create("queue.group", DISPATCH_QUEUE_CONCURRENT);

一个线程组
dispatch_group_t groupGCD = dispatch_group_create();

dispatch_group_async(groupGCD, queue, ^{
NSLog(@"开始 :task1");
});

dispatch_group_async(groupGCD, queue, ^{
NSLog(@"开始 :task2");
});

线程组的监听通知
dispatch_group_notify(groupGCD, queue, ^{
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"回到主线程");
});
});

你可能感兴趣的:(iOS之线程组)