Ios开发:改变线程优先级
2016-06-03 21:21
302 查看
简介
每个线程执行时都具有一定的优先级,对于UI线程的优先级约为0.75,对于新创建的子线程的默认优先级为0.5,对于优先级高的则会获得较高的执行的机会,为大家介绍一下怎样改变线程的优先级程序说明
新建一个sing view application,只需要修改程序委托类,其它不需要进行修改,新建了两个线程,使用thread.threadPriority方法改变了线程的优先级,但是在改变优先级之前输出了线程的优先级,run方法作为线程的执行体#import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; NSLog(@"线程UI的优先级为:%g",[NSThread threadPriority]); NSThread *thread1=[[NSThread alloc]initWithTarget:self selector:@selector(run) object:nil]; thread1.name=@"线程A"; NSLog(@"线程的优先级A为:%g",thread1.threadPriority); thread1.threadPriority=0.0; NSThread *thread2=[[NSThread alloc]initWithTarget:self selector:@selector(run) object:nil]; thread2.name=@"线程B"; NSLog(@"线程的优先级B为:%g",thread2.threadPriority); thread2.threadPriority=1.0; [thread1 start]; [thread2 start]; for (int i=0; i<100; i++) { NSLog(@"-----%@------%d",[NSThread currentThread],i); } } -(void)run { for (int i=0; i<100; i++) { NSLog(@"-----%@------%d",[NSThread currentThread].name,i); } } @end
结果显示及说明
相关文章推荐
- iOS的动画效果类型及实现方法
- iOS学习笔记-----GCD 用法介绍
- iOS 之 arc4random() 和 arc4random_uniform()的区别
- 如何做好IOS View的布局
- iOS开发之LLDB打印json数据显示中文
- iOS开发一些小技巧
- iOS Layout 技术回顾及 Masonry 介绍
- iOS开发 纯代码屏幕适配
- iOS下dyld: Library not loaded: 错误解决方法
- CAShapeLayer的简单实用(2)
- 关于 timeIntervalSince1970 计算出错的问题(4s)
- Pod管理的iOS项目修改工程名
- iOS8 tableview separatorInset cell分割线左对齐,ios7的方法失效了
- Block中对weakSelf进行strong处理
- 如果爱,请深爱:10大iOS开发者最喜爱的类库
- iOS简单、方便、好用的HZSigmentScrollView(二)
- iOS navigationbar的各种改色
- iOS 传值方法(属性传值、代理传值、Block、通知、单例)
- 在iOS中动态改变statusbar的颜色
- iOS开发笔记--使用blend改变图片颜色