iOS 队列

作者: 说不出口的喵 | 来源:发表于2017-12-08 16:57 被阅读18次

    dispatch_queue_t Queue = dispatch_queue_create("com.lanou3g.ConcurrentQueue", DISPATCH_QUEUE_CONCURRENT); //并

    dispatch_queue_t Queue2 = dispatch_queue_create("com.wl.MyQueue", DISPATCH_QUEUE_SERIAL); //串

    // /////// 串行队列 分两种    

    1.主队列

    2 自定义队列

           <1>  /创建串行队列、提交同步任务

                dispatch_queue_t queue = dispatch_queue_create("queueName",                     DISPATCH_QUEUE_SERIAL);

        dispatch_sync(queue, ^{

    //code 任务一

    });

    dispatch_sync(queue, ^{

    //code 任务二

    });

    队列中的任务是同步出列的,任务一执行结束后执行任务二。这种类型的任务与主线程是同步的,会阻塞主线程

    <2> 创建串行队列、提交异步任务

    dispatch_queue_t queue = dispatch_queue_create("queueName", DISPATCH_QUEUE_SERIAL);

    dispatch_async(queue, ^{

    //code 任务一

    });

    dispatch_async(queue, ^{

    //code 任务二

    });

    队列的任务是同步出列,任务一执行结束后执行任务二。该类型的任务与主线程是并发执行的,不会阻塞主线程

      /////////   并行队列 分俩种

     1dispatch_get_global_queue

     2自定义队列

        <1> 自定义并行队列,提交同步任务

    // 创建并行队列、提交同步任务

    dispatch_queue_t queue = dispatch_queue_create("queueName", DISPATCH_QUEUE_CONCURRENT);

    dispatch_async(queue, ^{

    //code 任务一

    });

    dispatch_async(queue, ^{

    //code 任务二

    });

    <2> 自定义并行队列,提交异步任务

    //创建并行队列、提交异步任务

    dispatch_queue_t queue = dispatch_queue_create("queueName", DISPATCH_QUEUE_CONCURRENT);

    dispatch_async(queue, ^{

    //code 任务一

    });

    dispatch_async(queue, ^{

    //code 任务一

    });

    任务一出列后任务二才可以出列,各任务之间是异步的,不会阻塞主线程

    http://blog.csdn.net/pangshishan1/article/details/48662277

    相关文章

      网友评论

        本文标题:iOS 队列

        本文链接:https://www.haomeiwen.com/subject/otzeixtx.html