标签:多线程
//创建一个线程,回到用控制器里面的run方法
NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(run) object:nil];
//线程创建了,并没有效果,需要启动线程
[thread start];
NSThread *thread = [NSThread currentThread];
调度优先级的取值范围是0.0 ~ 1.0,默认0.5,值越大,优先级越高
+ (double)threadPriority;
+ (BOOL)setThreadPriority:(double)p;
- (double)threadPriority;
- (BOOL)setThreadPriority:(double)p;
优点:简单快捷
缺点:无法对线程进行更详细的设置
[NSThread detachNewThreadSelector:@selector(run) toTarget:self withObject:nil];
[self performSelectorInBackground:@selector(run) withObject:nil];
+ (void)sleepUntilDate:(NSDate *)date;//开始睡眠,知道什么日期回来
+ (void)sleepForTimeInterval:(NSTimeInterval)ti;//睡多久
+ (void)exit;
@synchronized(锁对象) {
// 需要锁定的代码
}
一个线程执行的结果可以传给另一个线程执行
/*传递给主线程*/
- (void)performSelectorOnMainThread:(SEL)aSelector withObject:(id)arg waitUntilDone:(BOOL)wait;
/*传给自定义线程*/
- (void)performSelector:(SEL)aSelector onThread:(NSThread *)thr withObject:(id)arg waitUntilDone:(BOOL)wait;
标签:多线程
原文地址:http://blog.csdn.net/ttf1993/article/details/45694461