NSThread

创建和启动线程

一个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种创建线程方式的优缺点

优点:简单快捷

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

posted @ 2016-03-12 19:59  iFat  阅读(155)  评论(0)    收藏  举报