- 先看一下线程的状态

- 学习多线程的目的:就将耗时操作放到子线程中去执行。
- [NSThread currentThread] 获得当前方法执行的线程对象
- 通过number来判断当前线程是主线程还是子线程
- 提示:不要纠结这个number的值是多少
- 只要number == 1,则代表是主线程
- number != 1,则是子线程,这个值是由CPU决定,
- (void)threadDemo1 {
NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(longOperation:) object:@"alloc"];
[thread start];
}
- (void)longOperation:(id)param{
NSLog(@"%@---%@",param,[NSThread currentThread]);
}
- (void)threadDemo2 {
[NSThread detachNewThreadSelector:@selector(longOperation:) toTarget:self withObject:@"detach"];
}
- (void)threadDemo3{
[self performSelectorInBackground:@selector(longOperation:) withObject:@"performSelector"];
}