iOS多线程之NSThread
来源:互联网 发布:上海华师大网络教育 编辑:程序博客网 时间:2024/05/18 17:03
//// ViewController.m// iOS多线程之NSThread//// Created by yongpengliang on 16/3/7.// Copyright © 2016年 jerry. All rights reserved.//#import "ViewController.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; //创建子线程方法1:手动创建线程,并手动启动 //线程启动后在未执行完毕前,此处NSThread对象不会释放 NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(run) object:nil]; //启动线程 [thread start]; //创建子线程方法2:从当前线程分离出一个线程,并自动启动 [NSThread detachNewThreadSelector:@selector(run) toTarget:self withObject:nil]; //创建子线程方法3: [self performSelectorInBackground:@selector(run) withObject:nil];}/** * 子线程的执行代码 */- (void) run{ NSLog(@"%@",[NSThread currentThread]);}@end
打印结果:
2016-03-07 23:05:19.076 iOS多线程之NSThread[92481:1748616] {number = 2, name = (null)}
2016-03-07 23:05:19.076 iOS多线程之NSThread[92481:1748617] {number = 3, name = (null)}
2016-03-07 23:05:19.076 iOS多线程之NSThread[92481:1748618] {number = 4, name = (null)}
0 0
- 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
- IOS多线程开发之NSThread
- iOS多线程之Pthread/NSthread
- iOS多线程之Pthread/NSthread
- iOS多线程编程之NSThread
- iOS整理 -- 多线程之NSThread
- 06计算机优秀毕业论文-总结和展望
- 判断字符串是否为字母或数字【java】
- EffeciveJava-2 遇到多个参数时考虑使用构建器
- Webpack your bags(中文翻译)
- 结构体字节对齐
- iOS多线程之NSThread
- [leetcode 96]Unique Binary Search Trees--二叉搜索树的个数问题。
- 使用二维数组实现------判断2048小游戏的结束
- 星期几问题
- @Autowired注解、@Resource注解的区别
- MediaController
- 2.1jQuery 选择器
- 安装虚拟机VMware问题汇总
- 直接插入排序