第一种:NStread

 

 1 - (void)viewDidLoad {
 2 [super viewDidLoad];
 3 // Do any additional setup after loading the view, typically from a nib.
 4 
 5 /**
 6 * 实现多线程方式之一:NSThread
 7 */
 8 /*
 9 // 获取当前线程
10 NSLog(@"current = %@", [NSThread currentThread]);
11 // 获取主线程
12 NSLog(@"msinThread = %@", [NSThread mainThread]);
13 // 获取当前线程是否为主线程
14 NSLog(@"isMainThread = %d", [NSThread isMainThread]);
15 */
16 #pragma mark - NSThread 手动开辟子线程
17 // 第一个参数:target
18 // 第二个参数:方法
19 // 第三个参数:传参
20 // NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(threadAction) object:nil];
21 // 让多线程启动
22 // [thread start];
23 
24 // 使用NSThread和NSObject实现的开辟线程,系统会自动释放,关不关都行
25 // ( *** 了解 ) 结束线程的两种方式
26 // 取消线程 第一种方式
27 // [thread cancel]; // 不是真正取消,而是给线程发送有个信号,通过这个信号进行取消
28 // 直接退出线程 第二种方式
29 // [NSThread exit];
30 
31 #pragma mark - NSTread自动开辟子线程
32 // 线程自动开启
33 // 把手动开启的target和select两个参数顺序颠倒
34 // [NSThread detachNewThreadSelector:@selector(threadAction) toTarget:self withObject:nil];
35 }

 

转载于:https://www.cnblogs.com/crazygeek/p/5503947.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值