iOS并发处理的那些事(译自外文)
来源:互联网 发布:pkpm是什么软件 编辑:程序博客网 时间:2024/04/28 13:56
- (void) doCalculation{
/* Do your calculation here */
}
- (void) calculationThreadEntry{
@autoreleasepool {
NSUInteger counter = 0;
while ([[NSThread currentThread] isCancelled] == NO){[self doCalculation];counter++;
if (counter >= 1000){break;}
}}
}
- (BOOL) application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
/* Start the thread */
//这里用NSThread生成一个新的线程,calculationThreadEntry这个方法,在新的线程中执行。
//其中这里需要注意的一点就是,calculationThreadEntry中得操作要放在自动释放池中进行。
[NSThread detachNewThreadSelector:@selector(calculationThreadEntry)
toTarget:selfwithObject:nil];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
而如果我们要用GCD做同样的工作,则不用显得如此繁琐
dispatch_queue_t queue=dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0);
size_t numberOfIterations=1000;
dispatch_async(queue, ^(void){dispatch_apply(numberOfIterations, queue,^(size_titeration){
/* Perform the operation here */
});});
妹的,csdn太难用了- iOS并发处理的那些事(译自外文)
- IOS手势处理的那些坑
- IOS线程的并发与处理(翻译自:http://www.objc.io/issue-2/concurrency-apis-and-pitfalls.html)
- IOS并发处理的同步和通信
- IOS 并发处理
- IOS didReceiveMemoryWarning 的那些事
- IOS didReceiveMemoryWarning 的那些事
- IOS didReceiveMemoryWarning 的那些事
- iOS推送的那些事
- ios tableView那些事 (六) 如何处理tableView上的文字
- ios tableView那些事 (六) 如何处理tableView上的文字
- ios tableView那些事 (六) 如何处理tableView上的文字
- ios tableView那些事 (六) 如何处理tableView上的文字
- ios tableView那些事 (六) 如何处理tableView上的文字
- 外文的代码网站
- 找外文的介绍
- 嵌入式的外文网站
- 好听的外文歌曲
- UESTC 1546 Bracket Sequence(线段树 成段更新)
- N皇后问题的两个最高效的算法
- 嵌入式Web 服务器Boa 的移植及其应用
- VIM使用教程
- Msfpayload
- iOS并发处理的那些事(译自外文)
- SQL语句之单行函数
- properties editor for eclipse安装使用
- Study Linux - GDB调试
- hdu3336之KMP应用
- Start up JIAJIA
- PHP小功能-获取天气预报
- MAC 虚拟机安装过程问题解决
- Android中振动器(Vibrator)的使用