GCD 串行队列

dispatch_queue_t aQueue = dispatch_queue_create("groupname",DISPATCH_QUEUE_SERIAL);
// create queue group
dispatch_group_t queueGroup = dispatch_group_create();
// task 1
dispatch_group_async(queueGroup, aQueue, ^{
    NSLog(@"task 1 begin.");
    NSLog(@"task 1 end.");
});
// task 2
dispatch_group_async(queueGroup, aQueue, ^{
    NSLog(@"task 2 begin.");
    NSLog(@"task 2 end.");
});
// task 3
dispatch_group_async(queueGroup, aQueue, ^{
    NSLog(@"task 3 begin.");
    NSLog(@"task 3 end.");
});
NSLog(@"wait task 1,2,3.");
// waiting for group tasks done
dispatch_group_wait(queueGroup, DISPATCH_TIME_FOREVER);
NSLog(@"task 1,2,3 finished.");
// release group
dispatch_release(queueGroup);
// recreate group
queueGroup = dispatch_group_create();
// task 4
dispatch_group_async(queueGroup, aQueue, ^{
    NSLog(@"task 4 begin.");
    NSLog(@"task 4 end.");
});
// task 5
dispatch_group_async(queueGroup, aQueue, ^{
    NSLog(@"task 5 begin.");
    NSLog(@"task 5 end.");
});
// task 6
dispatch_group_async(queueGroup, aQueue, ^{
    NSLog(@"task 6 begin.");
    NSLog(@"task 6 end.");
});
NSLog(@"wait task 4,5,6.");
// waiting for group tasks done
dispatch_group_wait(queueGroup, DISPATCH_TIME_FOREVER);
NSLog(@"task 4,5,6 finished.");
// release group
dispatch_release(queueGroup);

你可能感兴趣的:(GCD 串行队列)