-(void)creatThread1
{
NSThread *thread = [[NSThread alloc]initWithTarget:self selector:@selector(run:) object:@"abc"];
thread.name = @"mythread";
[thread start];
}
-(void)creatThread2
{
//不要开启,无法设置线程名称
[NSThread detachNewThreadSelector:@selector(run:) toTarget:self withObject:@"miss"];
}
-(void)creatThread3
{
//开启后台线程
[self performSelectorInBackground:@selector(run:) withObject:@"background"];
}
-(void)run:(id)obj{
NSLog(@"current = %@",[NSThread currentThread]);
for (int i = 0; i < 100000; i ++) {
NSLog(@"--%d--",i);
}
}
线程休眠
[NSThread sleepForTimeInterval:2];
[NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:2]];
线程退出
[NSThread exit];