- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib.}- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent *)event {
//1 新建状态
NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(demo) object:nil];
//2 就绪状态 --》 运行状态
[thread start];
}
- (void)demo {
for (int i = 0 ; i < 10; i++) {
if (i == 5) {
//3 睡眠状态
[NSThread sleepForTimeInterval:5];
}
if (i == 7) {
//4 死亡状态
[NSThread exit];
}
NSLog(@"hello %d",i);
}
}