iOS解决多线程 线程阻塞问题
2015-10-21 18:21
369 查看
一:这样处理之后不会影响外部视图的展示,亲测可行
#import "ThreadSDK.h"
@interface ThreadSDK (){
BOOL threadDone;
}
@end
@implementation ThreadSDK
//测试接口
- (void)thread {
[self
performSelector:@selector(asynchronousSource)
withObject:nil
afterDelay:0];
NSLog(@"me");
threadDone =
NO;
do {
// Start the run loop but return after each source is handled.
SInt32 result =
CFRunLoopRunInMode(kCFRunLoopDefaultMode,
1, YES);
if ((result ==
kCFRunLoopRunStopped) || (result == kCFRunLoopRunFinished))
threadDone = YES;
}
while (!threadDone);
NSLog(@"me --- end");
}
//阻塞测试
- (void)asynchronousSource {
for (int i =
0; i < 5; i++) {
sleep(1);
NSLog(@"asynchronous input source run");
}
threadDone =
YES;
}
转自:http://www.cnblogs.com/jy578154186/archive/2013/02/26/2933974.html
#import "ThreadSDK.h"
@interface ThreadSDK (){
BOOL threadDone;
}
@end
@implementation ThreadSDK
//测试接口
- (void)thread {
[self
performSelector:@selector(asynchronousSource)
withObject:nil
afterDelay:0];
NSLog(@"me");
threadDone =
NO;
do {
// Start the run loop but return after each source is handled.
SInt32 result =
CFRunLoopRunInMode(kCFRunLoopDefaultMode,
1, YES);
if ((result ==
kCFRunLoopRunStopped) || (result == kCFRunLoopRunFinished))
threadDone = YES;
}
while (!threadDone);
NSLog(@"me --- end");
}
//阻塞测试
- (void)asynchronousSource {
for (int i =
0; i < 5; i++) {
sleep(1);
NSLog(@"asynchronous input source run");
}
threadDone =
YES;
}
转自:http://www.cnblogs.com/jy578154186/archive/2013/02/26/2933974.html
相关文章推荐
- NSFileManager的理解
- iOS中AutoLayer自动布局流程及相关方法
- iOS 远程推送
- iOS 安全攻防系列(一):HelloWorld
- iOS:Autolayout自动布局实例
- 通过添加设备UDID,打包iOS应用程序,ipa包安装。
- iOS开发 银行卡号有效性问题Luhn算法
- iOS KVO 实例
- iOS开发 精确的身份证号码有效性检测
- iOS Method Swizzling(交换)
- nagios报警延迟的解决--flapping state
- 文章标题
- iOS开发012 实例 启动画面 本地存储数据 多风格iOS7式segment
- IOS--单例类
- IOS----断点下载
- iOS开发中的一些细节
- iOS每日一记-----之 简单的按钮切换
- IOS 开源库介绍
- iOS中定时器NSTimer的使用
- IOS添加计时器的两种方法