//首先创建5个串行队列
dispatch_queue_t serialQueue1 = dispatch_queue_create("com.gcd.setTargetQueue2.serialQueue1", NULL);
dispatch_queue_t serialQueue2 = dispatch_queue_create("com.gcd.setTargetQueue2.serialQueue2", NULL);
dispatch_queue_t serialQueue3 = dispatch_queue_create("com.gcd.setTargetQueue2.serialQueue3", NULL);
dispatch_queue_t serialQueue4 = dispatch_queue_create("com.gcd.setTargetQueue2.serialQueue4", NULL);
dispatch_queue_t serialQueue5 = dispatch_queue_create("com.gcd.setTargetQueue2.serialQueue5", NULL);
//创建目标串行队列
dispatch_queue_t targetSerialQueue = dispatch_queue_create("com.gcd.setTargetQueue2.targetSerialQueue", NULL);
//设置执行阶层
dispatch_set_target_queue(serialQueue1, targetSerialQueue);
dispatch_set_target_queue(serialQueue2, targetSerialQueue);
dispatch_set_target_queue(serialQueue3, targetSerialQueue);
dispatch_set_target_queue(serialQueue4, targetSerialQueue);
dispatch_set_target_queue(serialQueue5, targetSerialQueue);
//执行操作
dispatch_async(serialQueue1, ^{
NSLog(@"1");
});
dispatch_async(serialQueue2, ^{
NSLog(@"2");
});
dispatch_async(serialQueue3, ^{
NSLog(@"3");
});
dispatch_async(serialQueue4, ^{
NSLog(@"4");
});
dispatch_async(serialQueue5, ^{
NSLog(@"5");
});
//有序
2017-02-28 21:38:06.606 GCDLearn[1506:75803] 1
2017-02-28 21:38:06.607 GCDLearn[1506:75803] 2
2017-02-28 21:38:06.607 GCDLearn[1506:75803] 3
2017-02-28 21:38:06.608 GCDLearn[1506:75803] 4
2017-02-28 21:38:06.608 GCDLearn[1506:75803] 5
网友评论