前言:复习一下多线程,脑子有点不够用记录下学习下。
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; // 进入死亡状态,一旦死亡则不能重启
本文介绍iOS中使用NSThread进行多线程编程的方法,包括动态创建与启动线程、设置线程名称及优先级等操作。同时,还提供了如何通过NSThread实现线程的阻塞与退出。

6862

被折叠的 条评论
为什么被折叠?



