GCD

作者: SecTwilight | 来源:发表于2016-07-03 19:50 被阅读0次

    //dispatch_barrier_async使用在并行环境下,
    //dispatch_barrier_async添加的任务会在之前的block全部运行完毕之后,才会继续执行,保证线程安全保证对非线程安全的对象进行正确的操作。
    //运行完dispatch_barrier_async才会执行后面的任务
    //dispatch_barrier_async所在的线程跟前一个任务是同一线程

    //延迟执行
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW,(int64_t)(5*NSEC_PER_SEC)),dispatch_get_main_queue,dispatch_get_main_queue(),^{
    NSLog(@"选择性队列延迟5秒执行");
    })
    //自定义并行队列
    dispatch_queue_t queue=dispatch_queue_create("duoduo",DISPATCH_QUEUE_CONCURRENT);
    dispatch_async(queue,^{
    NSLog(@"dispatch_async-1-%@",[NSThread currentThread]);
    });
    dispatch_async(queue,^{
    NSLog(@"dispatch_async-2-%@",[NSTread currentThread]);
    });
    dispatch_barrier_async(queue,^{
    NSLog(@"dispatch_barrier_async-%@",[NSTread currentThread]);
    });
    dispatch_async(queue,^{
    NSLog(@"dispatch_async-3-%@",[NSThread currentThread]);
    });
    dispatch_async(queue,^{
    NSLog(@"dispatch_async-4-%@",[NSThread currentThread]);
    });
    
    09BC3DCA-CF0F-475E-B3B8-644FDBCC1B9B.png

    相关文章

      网友评论

          本文标题:GCD

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