NSThread线程的状态-6
2016-05-26 本文已影响25人
Sunney
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
[NSThread detachNewThreadSelector:@selector(run) toTarget : self withObject:nil];
}
- (void)run{
NSLog(@”---------”);
//让线程睡眠2秒(阻塞2秒)
//[NSThread sleepForTimeInterval:2];
//睡眠直到遥远的未来
//[NSThread sleepUntilDate:[NSDate distanceFuture]];
[NSThread sleepUntilDate:[NSDate datewithTimeIntervalSinceNow:2]];
NSlog(@”+++++++”);
}
- (void)run1{
For(NSInteger i = 0; i < 100; i++){
NSLog(@“-----%ld”,i);
If(i == 49 ){
[NSThread exit];//直接退出线程
}
}
}