zoukankan      html  css  js  c++  java
  • IOS 多线程(2) --NSThread

    • 一个NSThread对象就代表一个线程(NSThread在多线程中其实用的不多)
    • 线程的创建和启动线程的几种方式
    // 第一种 常规
    NSThread  *thread =[[NSthread alloc] initWithTarget:self selector:@selector(run) object:nil];
    [thread start]; 
    // 第二种 创建线程后自动启动
    [ NSThread  datachNewThreadSelector:@selector(run) toTarget:self withObject:nil]; 
    
    
    // 第三种 隐式创建并启动线程
    [self performSelectorInBackground:@selector(run) withObject:nil];
    
    • 获得当前线程
    NSThread *current=[NSThread currentThread] ;
    • 线程的状态
      线程的状态分为创建(New)、就绪(Runnable)、运行(Running)、阻塞(Blocked)、死亡(Dead)五个状态。关系如下图
      这里写图片描述
    • 控制线程状态的常用方法
    + (void)sleepUntilDate:(NSDate *)date;
    + (void)sleepForTimeInterval:(NSTimeInterval)ti;
    + (void)exit;

    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    day_15补充加总结
    Day_15 内置模块er
    sort 函数 与 sorted 函数区别
    python 代码风格------------PEP8规则
    python 返回值
    函数记忆 : startswith() 与 endswith
    RE模块使用
    正则表达式
    collections
    函数datetime
  • 原文地址:https://www.cnblogs.com/yuqingzhude/p/4836540.html
Copyright © 2011-2022 走看看