多线程顺序执行

 //创建一个并行队列

    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]);

    });

posted on 2018-03-14 08:45  开花结果乐园  阅读(139)  评论(0编辑  收藏  举报

导航