OC中6种多线程的使用方式
来源:互联网 发布:云狐网络科技园怎么样 编辑:程序博客网 时间:2024/06/05 14:52
NSThread 实例创建;
NSThread类方法创建;
PerformSelectorOnBackground;
NSOperationQueue block添加operation;
NSOperationQueue直接添加operation;
dispatch_queue_create dispatch_async;
代码实现:
//one
NSThread *t = [[NSThreadalloc]initWithTarget:selfselector:@selector(mutableThread)object:nil];
[t start];
//two
[NSThreaddetachNewThreadSelector:@selector(mutableThread)toTarget:selfwithObject:nil];
//three
[selfperformSelectorInBackground:@selector(mutableThread)withObject:nil];
//four
NSOperationQueue *queue = [[NSOperationQueuealloc]init];
[queue addOperationWithBlock:^{
NSThread *thr = [[NSThreadalloc]init];
if (![thr isMainThread]) {
NSLog(@"是多线程");
}
}];
//five
NSOperationQueue *que = [[NSOperationQueuealloc]init];
NSInvocationOperation *op = [[NSInvocationOperationalloc]initWithTarget:selfselector:@selector(mutableThread)object:nil];
[que addOperation:op];
//six
dispatch_queue_t ddph =dispatch_queue_create("hehe",NULL);
dispatch_async(ddph, ^{
if (![[NSThreadcurrentThread] isMainThread]) {
NSLog(@"是多线程");
}
});
- OC中6种多线程的使用方式
- OC中多线程的使用、概念、创建方式、生命周期、使用注意等
- OC中声明变量的几种方式
- oc中数组的四种遍历方式及比较
- OC中变量的两种声明方式分析
- OC中数组的四种遍历方式
- OC中声明Block的几种方式
- OC中多线程的创建方法
- OC中多线程的一些概念
- OC中多线程执行顺序的控制
- 使用OC加载图片的两种方式及其区别
- 使用OC加载图片的两种方式及其区别
- 创建使用多线程的 三种方式
- 多线程的使用(4) - iOS多线程的三种方式
- 多线程的使用(4) - iOS多线程的三种方式
- 多线程的使用(4) - iOS多线程的三种方式
- 探讨OC中字典的存储方式
- OC中私有变量的定义方式
- 二叉树的遍历
- christian louboutin men and Deng Deng Jiaying expressed the hope that the idea of � oing his girl
- [小技巧] Notepad++关闭拼写检查
- tiffany outlet italia CD action
- abercrombie outlet causing the school attention. 16
- OC中6种多线程的使用方式
- qmake的使用简介
- python使用matplotlib绘图 -- barChart
- Linux下select, poll和epoll IO模型的详解
- OGRE CG教程 (一):OGRE CG 基础
- 传真数据交换平台的构建
- [LeetCode] Max Points on a Line
- Java代码加密与反编译(二):用加密算法DES修改classLoader实现对.class文件加密
- 解决:Android编译源码根目录下/system/vold后,通过push命令将编译生成的vold文件push至system/bin下无法正常开机