博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
OC中多线程的创建方法
阅读量:7233 次
发布时间:2019-06-29

本文共 1225 字,大约阅读时间需要 4 分钟。

方法一:

NSThread *t = [[NSThread alloc] initWithTarget:self selector:@selector(mutableThread) object:nil];

方法二:

[NSThread detachNewThreadSelector:@selector(mutableThread) toTarget:self withObject:nil];

方法三:

[self performSelectorInBackground:@selector(mutableThread) withObject:nil];

方法四:多线程blog创建

NSOperationQueue *operationQueue = [[NSOperationQueue alloc] init];

//会开启一个多线程

[operationQueue addOperationWithBlock:^{

for(int i = 0; i < 50 ;i++)

{

NSLog(@"多线程:%d",i);

}

}];

方法五:

//相当于是一个线程池

NSOperationQueue *operationQueue = [[NSOperationQueue alloc] init];

operationQueue.maxConcurrentOperationCount = 1;//设置并发数

//创建线程

NSInvocationOperation *opertion1 = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(thread1) object:nil];

//设置线程的优先级

[opertion1 setQueuePriority:NSOperationQueuePriorityVeryLow];

//创建另一个线程

NSInvocationOperation *opertion2 = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(thread2) object:nil];

[opertion2 setQueuePriority:NSOperationQueuePriorityHigh];

方法六:

dispatch_queue_t queue = dispatch_queue_create("test",NULL);

dispatch_async(queue,^{

for(int i=0;i<50;i++)

{

NSLog(@"多线程:%d",i);

});

本文转蓬莱仙羽51CTO博客,原文链接:http://blog.51cto.com/dingxiaowei/1366562,如需转载请自行联系原作者

你可能感兴趣的文章
Java 实现单链表反序
查看>>
移植alsa-lib遇到的问题
查看>>
镜像的缓存特性 - 每天5分钟玩转 Docker 容器技术(14)
查看>>
[Node.js]多进程
查看>>
面试归来,感觉无望,下次再战
查看>>
C#之值类型和引用类型
查看>>
项目经理的五种权利
查看>>
病态矩阵与条件数
查看>>
Java IntelliJ IDEA 不能显示项目里的文件结构
查看>>
HDU 5325 Crazy Bobo(思路+dfs 记忆化)
查看>>
.NET平台常用的框架整理
查看>>
使用EmbeddedValueResolverAware读取配置文件内容
查看>>
打印从1到最大的n位数
查看>>
drawnet.py绘制网络结构
查看>>
Javascript中apply、call、bind
查看>>
电脑显示U盘,可是读取不了
查看>>
Linux时间子系统之八:动态时钟框架(CONFIG_NO_HZ、tickless)
查看>>
LLVM/Clang
查看>>
九周 项目 1
查看>>
南昌互联网行业协会筹办者祝真和华罡团队-2014年12月江西IDC排行榜
查看>>