多线程顺序执行
//创建一个并行队列
dispatch_queue_t queue = dispatch_queue_create("carType", DISPATCH_QUEUE_SERIAL);
//在并行队列里创建四个异步任务,输出一句话
dispatch_async(queue, ^{
NSLog(@"我是第0个任务, 当前线程:%@ ,是否主线程%d",[NSThread currentThread],[NSThread isMainThread]);
});
//并输出“当前线程”(内容包括线程编号和线程名(如果你命名了的话)),输出"是否主线程"
dispatch_async(queue, ^{
NSLog(@"我是第一个任务, 当前线程:%@ ,是否主线程%d",[NSThread currentThread],[NSThread isMainThread]);
});
dispatch_async(queue, ^{
NSLog(@"我是第二个任务, 当前线程:%@ ,是否主线程%d",[NSThread currentThread],[NSThread isMainThread]);
});
dispatch_async(queue, ^{
NSLog(@"我是第三个任务, 当前线程:%@ ,是否主线程%d",[NSThread currentThread],[NSThread isMainThread]);
});