NSThread

2019-06-03  本文已影响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];
上一篇 下一篇

猜你喜欢

热点阅读