使用runloop阻塞线程的正确写法
2013-02-26 01:09
411 查看
使用runloop阻塞线程的正确写法
http://marshal.easymorse.com/archives/4700runloop可以阻塞线程,等待其他线程执行后再执行。比如:@implementation ViewController{
BOOL end;
}
…
– (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@”start new thread …”);
[NSThread detachNewThreadSelector:@selector(runOnNewThread) toTarget:self withObject:nil];
while (!end) {
NSLog(@”runloop…”);
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
NSLog(@”runloop end.”);
}
NSLog(@”ok.”);
}
-(void)runOnNewThread{
NSLog(@”run for new thread …”);
sleep(1);
end=YES;
NSLog(@”end.”);
}但是这样做,运行时会发现,while循环后执行的语句会在很长时间后才被执行。
相关文章推荐
- 使用runloop阻塞线程的正确写法
- 使用runloop阻塞线程的正确写法
- 使用runloop阻塞线程的正确写法
- 使用runloop阻塞线程的正确写法
- 使用runloop阻塞线程
- 在子线程中使用runloop,正确操作NSTimer计时的注意点 三种可选方法
- runloop实现原理初解 和 使用runloop阻塞线程
- ios下使用runloop阻塞线程
- 使用runloop阻塞线程
- 在子线程中使用runloop,正确操作NSTimer计时的注意点 三种可选方法
- 在子线程中使用runloop,正确操作NSTimer计时的注意点 三种可选方法
- 解决使用Delphi的Thread时主线程阻塞
- nodejs读取文件时相对路径的正确写法(使用fs模块)
- IOS在子线程中使用定时器,将定时器添加至RunLoop中(转)
- 终止线程 Response.End 在Asp.net 里面的正确使用
- Nodejs读取文件时相对路径的正确写法(使用fs模块)
- Java中使用阻塞队列控制线程集实例
- Java 使用线程经验之阻塞队列
- java线程阻塞中断与LockSupport使用介绍
- 在 Windows 7 下如何使用 native c++ 正确创建线程