ios并发编程的总结
2013-05-24 11:09
357 查看
最近这段时间,花了很多精力,仔细的学习了ios并发编程相关的内容,对并发编程的理解有了更深刻、全面的认识,现做一个简单的总结。
一,ios中实现并发有哪几种方式?
GCD,NSQueueOperation,NSTimer,NSThread。
二,上面四种实现方式,具体是有哪些常用的接口及注意事项:
1,GCD
dispatch_queue_t currentQueue = dispatch_get_globle_queue(DISPATCH_QUEUE_PRIORITY,0);
dispath_async(currentQueue,^(void)
{
NSLog(@"do something");
});
dispatch_get_main_queue();
dispatch_once_t
dispatch_sync()
dispatch_after(); //需要注意,以纳秒为单位
dispatch_groupt taskGroup = dispatch_group_create();
dispatch_group_async(taskGroup,mainQueue,^(void)
{
NSLog(@"do something");
})
dispatch_group_notify(taskGroup,mainQueue,^{
NSLog(@"finish");
})
dispatch_release(taskGroup);
2,NSTimer
//稍后继续。
scheduledTimerWithTimeInterval:target:selector:userInfo:repeats //这是runloop自动管理的。
如果生成了timer的实例,在退出(释放掉)当前controller之前,应该将timer invalidate掉。(注意,在dealloc中调用invalidate是无效的)
3,NSThread
detachNewThreadSelector:target:withObject:
performSelectorInBackground
在以前的sdk,中方法必须加上@autoreleasepool才能编译通过,但是我实验了一下,在xcode 4.6中,不加也能正常运行,ios 5 programing cocabook 上说的也不一定全部都是对的。
ok,基本总结完成了,希望能对大家理解ios并发编程的理解有所帮助。
一,ios中实现并发有哪几种方式?
GCD,NSQueueOperation,NSTimer,NSThread。
二,上面四种实现方式,具体是有哪些常用的接口及注意事项:
1,GCD
dispatch_queue_t currentQueue = dispatch_get_globle_queue(DISPATCH_QUEUE_PRIORITY,0);
dispath_async(currentQueue,^(void)
{
NSLog(@"do something");
});
dispatch_get_main_queue();
dispatch_once_t
dispatch_sync()
dispatch_after(); //需要注意,以纳秒为单位
dispatch_groupt taskGroup = dispatch_group_create();
dispatch_group_async(taskGroup,mainQueue,^(void)
{
NSLog(@"do something");
})
dispatch_group_notify(taskGroup,mainQueue,^{
NSLog(@"finish");
})
dispatch_release(taskGroup);
2,NSTimer
//稍后继续。
scheduledTimerWithTimeInterval:target:selector:userInfo:repeats //这是runloop自动管理的。
如果生成了timer的实例,在退出(释放掉)当前controller之前,应该将timer invalidate掉。(注意,在dealloc中调用invalidate是无效的)
3,NSThread
detachNewThreadSelector:target:withObject:
performSelectorInBackground
在以前的sdk,中方法必须加上@autoreleasepool才能编译通过,但是我实验了一下,在xcode 4.6中,不加也能正常运行,ios 5 programing cocabook 上说的也不一定全部都是对的。
ok,基本总结完成了,希望能对大家理解ios并发编程的理解有所帮助。
相关文章推荐
- iOS并发编程对比总结,NSThread,NSOperation,GCD - iOS
- PHP编程中尝试程序并发的几种方式总结
- iOS并发编程指南
- 【Java并发编程】之十七:深入Java内存模型—内存操作规则总结
- 关于Java并发编程的总结和思考
- 10007---关于Java并发编程的总结和思考
- iOS图形编程总结
- 并发编程学习总结(三) : 线程的中断详解
- OS X/iOS 并发编程小结
- Python多进程并发与多线程并发编程实例总结
- iOS多线程编程:线程同步总结
- iOS并发编程指南
- iOS编程技巧总结之语音篇(三)- OpenEars框架及其使用2
- iOS并发编程
- Java 并发编程知识点学习总结 (1)
- 并发编程学习总结
- iOS 并发编程若干问
- ios 网络编程总结
- iOS 各种网络编程总结--进程、线程、Socket、HTTP、TCP/IP、TCP和UDP
- iOS 开发 之网络编程简单总结转载