NSThread

作者: 鐧箪 | 来源:发表于2019-06-03 09:25 被阅读0次
NSThread

NSThread是苹果官方提供的 因为面向对象所以使用起来相对与pthread简单
当然它需要我们手动来管理线程的生命周期

NSThread的创建方式有三种

1.使用init方式创建

NSThread * onethread = [[NSThread alloc] initWithTarget:self selector:@selector(run) object:nil];
[onethread start];

2.类方法创建 并启动线程

[NSThread detachNewThreadSelector:@selector(run) toTarget:self withObject:nil];

3.隐式创建并启动线程

[self performSelectorInBackground:@selector(run)  withObject:nil];

相关文章

网友评论

      本文标题:NSThread

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