ios学习 多线程NSThread 基本属性
来源:互联网 发布:网络借贷不还会坐牢吗 编辑:程序博客网 时间:2024/05/29 08:15
- (void)viewDidLoad {
[superviewDidLoad];
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
[selfdemo2];
}
-(void)demo{
//第一种方法,需启动
NSThread *thread = [[NSThreadalloc]initWithTarget:selfselector:@selector(task)object:nil];
thread.name =@"one";
[thread start];
NSThread *thread2 = [[NSThreadalloc]initWithTarget:selfselector:@selector(task)object:nil];
thread2.name =@"two";
[thread2 start];
// //第二种方法,无需启动
// [NSThread detachNewThreadSelector:@selector(task) toTarget:self withObject:nil];
// //第三种方法,隐式创建线程
// [self performSelectorInBackground:@selector(task) withObject:nil];
}
//优先级
-(void)demo2{
NSThread *thread = [[NSThreadalloc]initWithTarget:selfselector:@selector(task)object:nil];
//线程的优先级,取值范围0.0 - 1.0;默认为0.5
thread.threadPriority =0;
//线程命名,方便调试
thread.name =@"-----------one";
[thread start];
NSThread *thread2 = [[NSThreadalloc]initWithTarget:selfselector:@selector(task)object:nil];
thread2.name =@"two";
[thread2 start];
}
-(void)task{
// NSLog(@"task is running %@",[NSThread currentThread]);
//
// NSLog(@"睡了");
// //阻塞
//// [NSThread sleepForTimeInterval:2]; //睡眠2秒
// [NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:5]]; //距离当前时间5秒
//
// NSLog(@"醒了");
// //手动杀死线程
// [NSThread exit];
// NSLog(@"died");
for (int i =0; i < 20; i++) {
NSLog(@"%@ %d", [NSThreadcurrentThread],i);
}
}
- ios学习 多线程NSThread 基本属性
- iOS多线程学习---NSThread
- iOS学习笔记-多线程基础(NSThread)
- IOS多线程系统学习之NSThread
- iOS多线程学习-NSThread、Cocoa NSOperation、GCD
- iOS-多线程编程学习之NSThread(三)
- [iOS学习]关于多线程和NSThread
- IOS学习 多线程NSThread 共享变量 卖票
- iOS 多线程 NSThread
- IOS 多线程 NSThread
- iOS多线程 nsthread
- ios NSThread多线程
- iOS多线程开发 NSThread
- IOS 多线程 线程NSThread
- iOS多线程之NSThread
- iOS多线程开发 NSThread
- ios多线程之NSThread
- IOS 多线程 线程NSThread
- android中媒体扫描服务mediaScannerService
- 重加加戴TABLE
- Android SDK Manager中options设置解决下载太慢问题
- 第五周上机实践项目——项目4-长方柱类
- 关于false aliasing的一些看法
- ios学习 多线程NSThread 基本属性
- 安卓开发的时候需要注意的点和坑!
- 利用中介者模式模拟两个对象对话 C++
- shell脚本--部署应用到tomcat并启动tomcat
- GCD的使用
- SpringMVC与Struts2区别与比较总结
- 书到用时方嫌少,多读些书
- poj 2136 Vertical Histogram
- Team Queue的解题报告