前言:复习一下多线程,脑子有点不够用记录下学习下。
Demo线程Demo
iOS多线程NSThread
个人而言NSThread相对于NSOperation和GCD更加简单一点,每一个NSThread创建一个线程,创建完成之后需要手动开启。
第一种 动态创建
NSThread *thread =[[NSThread alloc]initWithTarget:self selector:@selector(first) object:nil];
thread.name =@"线程1";
thread.threadPriority =1;// 优先级 0-1越高优先级越大
[thread start]; // 手动开启
静态创建 创建完成之后立马开启线程
[NSThread detachNewThreadSelector:@selector(second) toTarget:self withObject:@"More"];
- (void)start; 开启线程
+ (void)sleepUntilDate:(NSDate *)date;//阻塞(暂停)线程
+ (void)sleepForTimeInterval:(NSTimeInterval)ti;
// 进入阻塞状态
+ (void)exit; // 进入死亡状态,一旦死亡则不能重启