美文网首页
NSThread线程的四种状态

NSThread线程的四种状态

作者: 笑熬齊澄 | 来源:发表于2017-12-11 19:23 被阅读6次

- (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);

}

}

相关文章

网友评论

      本文标题:NSThread线程的四种状态

      本文链接:https://www.haomeiwen.com/subject/xrrwixtx.html