多線程主要分爲三種:NSThread、NSoperationQueue、GCD多線程
NSThread 相比其餘兩個比較輕量級,建立線程簡單,可是須要咱們本身管理該線程,操做線程比較麻煩。不僅是啓動,還有該線程使 用完畢後的資源回收;線程
NSThread * thread = [[NSThread alloc]initWithTarget:self selector:@selector(run) object:nil];資源
thread.name = @"子線程";//能夠爲開闢的線程起名字get
[thread start];//線程開始it
[thread cancel];//線程取消io
NSLog(@"initWithBlock");thread
[self run];object
}]; select
[thread start];opera
第三種:建立線程後自動啓動線程
[NSThread detachNewThreadSelector:@selector(run) toTarget:self withObject:nil];