1. 异步线程+串行队列 新开辟一条线程。串行执行
dispatch_queue_t chuanQue=dispatch_queue_create("chuan", DISPATCH_QUEUE_SERIAL);
dispatch_async(chuanQue, ^{
for (int i=0; i<50; i++) {
NSLog(@"%@A线程的%d",[NSThread currentThread],i);
}
});
dispatch_async(chuanQue, ^{
for (int i=0; i<50; i++) {
NSLog(@"%@B线程的%d",[NSThread currentThread],i);
}
});
// 1.获得全局的并发队列
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
// 2.将任务加入队列
dispatch_async(queue, ^{
for (NSInteger i = 0; i<10; i++) {
NSLog(@"1-----%@", [NSThread currentThread]);
}
});
dispatch_async(queue, ^{
for (NSInteger i = 0; i<10; i++) {
NSLog(@"2-----%@", [NSThread currentThread]);
}
});
dispatch_async(queue, ^{
for (NSInteger i = 0; i<10; i++) {
NSLog(@"3-----%@", [NSThread currentThread]);
}
});