- 一个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;
版权声明:本文为博主原创文章,未经博主允许不得转载。