zoukankan      html  css  js  c++  java
  • 第1年4月15日

    1.

    场景需求:需要异步完成三个任务。任务一、任务二、任务三。要求:任务三必须在任务一、任务二完成之后触发。这就需要使用dispatch_barrier_async。

        dispatch_queue_t queue = dispatch_queue_create("myQueue", DISPATCH_QUEUE_CONCURRENT);
        dispatch_async(queue, ^{
            //任务1
            for (int i = 0; i < 2; i++) {
                NSLog(@"我是任务一、来自线程:%@",[NSThread currentThread]);
            }
        });
        dispatch_async(queue, ^{
            //任务2
            for (int i = 0; i < 2 ; i++) {
                NSLog(@"我是任务二、来自线程:%@",[NSThread currentThread]);
            }
        });
        
        
        dispatch_barrier_async(queue, ^{
            //栅栏
            for (int i = 0; i < 1 ; i++) {
                NSLog(@"我是分割线、来自线程:%@",[NSThread currentThread]);
            }
        });
        
        dispatch_async(queue, ^{
            //任务3
            for (int i = 0; i < 1 ; i++) {
                NSLog(@"我是任务三、来自线程:%@",[NSThread currentThread]);
            }
        });

    https://juejin.cn/post/6844903767419125774

    2.gcd group

    https://juejin.cn/post/6844903766987276302

  • 相关阅读:
    多线程
    文件上传案例及多线程版本
    TCP、UDP网络通信
    刷题:蘑菇街最小移动次数
    刷题:蘑菇街回文串
    刷题:蘑菇街
    Range Sum Query
    Submission Details
    Reverse Words in a String
    Counting Bits
  • 原文地址:https://www.cnblogs.com/javastart/p/14663599.html
Copyright © 2011-2022 走看看