zoukankan      html  css  js  c++  java
  • NSThread

    创建和启动线程

    一个NSThread对象就代表一条线程

    创建、启动线程

    NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(run) object:nil];

    [thread start]; // 线程一启动,就会在线程thread中执行self的run方法

    其他创建线程方式

    创建线程后自动启动线程

    [NSThread detachNewThreadSelector:@selector(run) toTarget:self withObject:nil];

    隐式创建并启动线程

    [self performSelectorInBackground:@selector(run) withObject:nil];

    上述2种创建线程方式的优缺点

    优点:简单快捷

    缺点:无法对线程进行更详细的设置

  • 相关阅读:
    第四次作业
    第三次作业
    作业,11
    作业,10
    作业,9
    作业,8
    作业,7
    作业,6
    作业,5
    作业,4
  • 原文地址:https://www.cnblogs.com/xufengyuan/p/5269881.html
Copyright © 2011-2022 走看看