码迷,mamicode.com
首页 > 其他好文 > 详细

NSThread

时间:2016-03-12 21:05:40      阅读:185      评论:0      收藏:0      [点我收藏+]

标签:

创建和启动线程

一个NSThread对象就代表一条线程

创建、启动线程

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

[thread start]; // 线程一启动,就会在线程thread中执行self的run方法

 

其他创建线程方式

创建线程后自动启动线程

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

隐式创建并启动线程

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

上述2种创建线程方式的优缺点

优点:简单快捷

缺点:无法对线程进行更详细的设置

NSThread

标签:

原文地址:http://www.cnblogs.com/xufengyuan/p/5269881.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!