zoukankan      html  css  js  c++  java
  • 刀哥多线程之gcd-01-sync&async

    同步 & 异步

    概念

    • 同步
      • 必须等待当前语句执行完毕,才会执行下一条语句
    • 异步
      • 不用等待当前语句执行完毕,就可以执行下一条语句

    NSThread 中的 同步 & 异步

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
        NSLog(@"start");
    
        // 同步执行
    //    [self demo];
        // 异步执行
        [self performSelectorInBackground:@selector(demo) withObject:nil];
    
        NSLog(@"over");
    }
    
    - (void)demo {
    
        NSLog(@"%@", [NSThread currentThread]);
        [NSThread sleepForTimeInterval:1.0];
        NSLog(@"demo 完成");
    }

    代码小结

    • 同步 从上到下顺序执行
    • 异步多线程的代名词
  • 相关阅读:
    记账本开发第一天-补
    20200418-补
    20200411-补
    20200404-补
    20200328-补
    暴力解N皇后
    nN皇后递归
    Hanoi汉诺塔非递归栈解
    Hanoi汉诺塔递归
    JMMjmm模型
  • 原文地址:https://www.cnblogs.com/jiahao89/p/5118290.html
Copyright © 2011-2022 走看看