标签:style blog color 使用 strong 文件
NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(run) object:nil]; [thread start];
[NSThread detachNewThreadSelector:@selector(run) toTarget:self withObject:nil];
[self performSelectorInBackground:@selector(run) withObject:nil];
[self performSelectorInBackground:@selector(run) withObject:nil];
后两种开线程方法的相比于第一种 的优缺点:
主线程相关用法 + (NSThread *)mainThread; // 获得主线程 - (BOOL)isMainThread; // 是否为主线程 + (BOOL)isMainThread; // 是否为主线程
NSThread *current = [NSThread currentThread];//获得当前线程
+ (double)threadPriority; + (BOOL)setThreadPriority:(double)p; - (double)threadPriority; - (BOOL)setThreadPriority:(double)p; /*调度优先级的取值范围是0.0 ~ 1.0,默认0.5,值越大,优先级越高*/
- (void)setName:(NSString *)n; - (NSString *)name;
NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(run) object:nil]; [thread start];
- (void)start;
+ (void)sleepUntilDate:(NSDate *)date; + (void)sleepForTimeInterval:(NSTimeInterval)ti; // 进入阻塞状态
+ (void)exit; // 进入死亡状态
@synchronized(锁对象) { // 需要锁定的代码 }
@property (assign, atomic) int age; - (void)setAge:(int)age { @synchronized(self) { _age = age; } }
- (void)performSelectorOnMainThread:(SEL)aSelector withObject:(id)arg waitUntilDone:(BOOL)wait; - (void)performSelector:(SEL)aSelector onThread:(NSThread *)thr withObject:(id)arg waitUntilDone:(BOOL)wait;
iOS多线程实现方案详解01——NSThread,布布扣,bubuko.com
标签:style blog color 使用 strong 文件
原文地址:http://www.cnblogs.com/honghubanxian/p/3821477.html