OC 线程操作 - GCD快速迭代
- (void)forDemo{
//全都是在主线程操作的
for (NSInteger i = ; i<; i++) {
NSLog(@"--%@", [NSThread currentThread]);
}
/*
2018-06-27 11:33:44.226664+0800 5线程操作-GCD-快速迭代[7715:77291] --<NSThread: 0x60800006a9c0>{number = 1, name = main}
2018-06-27 11:33:44.226845+0800 5线程操作-GCD-快速迭代[7715:77291] --<NSThread: 0x60800006a9c0>{number = 1, name = main}
2018-06-27 11:33:44.227048+0800 5线程操作-GCD-快速迭代[7715:77291] --<NSThread: 0x60800006a9c0>{number = 1, name = main}
2018-06-27 11:33:44.227711+0800 5线程操作-GCD-快速迭代[7715:77291] --<NSThread: 0x60800006a9c0>{number = 1, name = main}
2018-06-27 11:33:44.227796+0800 5线程操作-GCD-快速迭代[7715:77291] --<NSThread: 0x60800006a9c0>{number = 1, name = main}
2018-06-27 11:33:44.227927+0800 5线程操作-GCD-快速迭代[7715:77291] --<NSThread: 0x60800006a9c0>{number = 1, name = main}
2018-06-27 11:33:44.227986+0800 5线程操作-GCD-快速迭代[7715:77291] --<NSThread: 0x60800006a9c0>{number = 1, name = main}
2018-06-27 11:33:44.228046+0800 5线程操作-GCD-快速迭代[7715:77291] --<NSThread: 0x60800006a9c0>{number = 1, name = main}
2018-06-27 11:33:44.228111+0800 5线程操作-GCD-快速迭代[7715:77291] --<NSThread: 0x60800006a9c0>{number = 1, name = main}
2018-06-27 11:33:44.228165+0800 5线程操作-GCD-快速迭代[7715:77291] --<NSThread: 0x60800006a9c0>{number = 1, name = main}
*/
}
-(void)GCD_apply{
/**
参数1:size_t iterations 便利次数
参数1:dispatch_queue_t _Nonnull queue 队列:只能穿进去并发队列,主队列 会死锁 ,串行队列和for循环一样效果在主队列,
参数1:<#^(size_t)block#> ^(size_t 索引) {
}
主队列也会参与这个操作, 并发执行
*/
dispatch_apply(, dispatch_get_global_queue(, ), ^(size_t index) {
NSLog(@"dispatch_get_global_queue ---- %zd--%@", index,[NSThread currentThread]);
});
dispatch_queue_t queue = dispatch_queue_create("并发", DISPATCH_QUEUE_CONCURRENT);
dispatch_apply(, queue, ^(size_t index) {
NSLog(@"DISPATCH_QUEUE_CONCURRENT ---- %zd--%@", index,[NSThread currentThread]);
});
/*
2018-06-27 11:41:46.924361+0800 5线程操作-GCD-快速迭代[7877:85649] 0--<NSThread: 0x608000074ac0>{number = 1, name = main}
2018-06-27 11:41:46.924467+0800 5线程操作-GCD-快速迭代[7877:85688] 2--<NSThread: 0x60400007de40>{number = 4, name = (null)}
2018-06-27 11:41:46.924468+0800 5线程操作-GCD-快速迭代[7877:85691] 3--<NSThread: 0x60c000465cc0>{number = 5, name = (null)}
2018-06-27 11:41:46.924469+0800 5线程操作-GCD-快速迭代[7877:85690] 1--<NSThread: 0x608000265a00>{number = 3, name = (null)}
2018-06-27 11:41:46.924526+0800 5线程操作-GCD-快速迭代[7877:85649] 4--<NSThread: 0x608000074ac0>{number = 1, name = main}
2018-06-27 11:41:46.924554+0800 5线程操作-GCD-快速迭代[7877:85688] 5--<NSThread: 0x60400007de40>{number = 4, name = (null)}
2018-06-27 11:41:46.924568+0800 5线程操作-GCD-快速迭代[7877:85691] 6--<NSThread: 0x60c000465cc0>{number = 5, name = (null)}
2018-06-27 11:41:46.924602+0800 5线程操作-GCD-快速迭代[7877:85649] 8--<NSThread: 0x608000074ac0>2018-06-27 11:41:46.924639+0800 5线程操作-GCD-快速迭代[7877:85688] 9--<NSThread: 0x60400007de40>{number = 4, name = (null)}
{number = 1, name = main}
2018-06-27 11:41:46.924604+0800 5线程操作-GCD-快速迭代[7877:85690] 7--<NSThread: 0x608000265a00>{number = 3, name = (null)}
*/
}
OC 线程操作 - GCD快速迭代的更多相关文章
- OC 线程操作 - GCD队列组
1.队列组两种使用方法2.队列组等待 wait /** 新方法 队列组一般用在在异步操作,在主线程写队列组毫无任何作用 */ - (void)GCD_Group_new_group___notify{ ...
- OC 线程操作 - GCD使用 -同步函数,异步函数,串行队列,并发队列
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ // GCD 开几条线程并不是我们 ...
- OC 线程操作 - GCD使用 -线程通讯, 延迟函数和一次性代码
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ // [self downImag ...
- OC线程操作-GCD介绍
1. GCD介绍 1.11.2 1.3 异步具备开启能力但是不是 一定可以开启 1.4 1.5 67. 8.
- OC 线程操作 - GCD使用 - 栅栏函数
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ //同步函数无需栅栏函数 //栅栏 ...
- OC 线程操作2 - NSThread
方法1 :直接创建 alloc init - (void)createNSThread111{ /* 参数1: (nonnull id) 目标对象 self 参数2:(nonnull SEL) ...
- OC 线程操作3 - NSOperation
#import "ViewController.h" @interface ViewController () @end @implementation ViewControlle ...
- OC 线程操作1 - pthread
#import "ViewController.h" #import <pthread.h> //1.需要包含这个头文件 @interface ViewControll ...
- OC 线程操作3 - NSOperation 实现线程间通信
#import "ViewController.h" @interface ViewController () /** 图片 */ @property (weak, nonatom ...
随机推荐
- [UE4]C++创建对象的三种方式
#include <iostream> using namespace std; class A { private: int n; public: A(int m):n(m) { } ~ ...
- javascript面向对象的程序设计之Object.getOwnPropertyDescriptor()
Object.getOwnPropertyDescriptor()用于获取给定属性的描述信息,这个描述信息是一个对象. 如果是访问器属性,则这个对象的属性有configurable,enumerabl ...
- 6.12-PrepareStatement,JdbcUtil 读取数据库配置文件properties,dao模式
一.PrepareStatement 防止sql注入 PrepareStatement 是预编译sql语句 更加灵活,更有效率 executeUpdate() 做增删改 executeQuery() ...
- unity3d之GUI
1.Button void OnGUI() { , , , ), "up")) {flg=true; } , , , ), "down")) {flg=fals ...
- SQL FORMAT() 函数实例
FORMAT()函数用于对字段的显示进行格式化. SQL FORMAT() 语法 SELECT FORMAT(column_name,format) FROM table_name; 参数 描述 co ...
- Linux火焰图-ubuntu
关注火焰图非常长的时间了!~~一直未能自己做个火焰图出来.今天小试一把. ubuntu18.04 ssh登陆之后执行命令 安装软件 apt-get install -y linux-cloud-too ...
- 使用CMQ和SCF实现邮件发送
准备腾讯云 API 调用工具 使用 API 命令行工具来管理和运行无服务器云函数(SCF),下面就先来安装配置该工具. 安装 Python 和 PIP Python 环境是腾讯云命令行工具运行时的必要 ...
- 代码生成器 CodeSmith 的使用(六)
在上一篇的版本中,我们生成了数据库所有表中的字段,如果要使数据库中的单个表 生成 PetaPoco 构架下的 ORM 映射,使那怎么办.这是这篇博客的主要内容. 首先来看完整的 Camel 规则模板: ...
- tensorflow data's save and load
note: if you'll load data,the data shape should be similar with saved data's shape. -- 中式英语,天下无敌 ...
- 机器学习入门-贝叶斯构造LDA主题模型,构造word2vec 1.gensim.corpora.Dictionary(构造映射字典) 2.dictionary.doc2vec(做映射) 3.gensim.model.ldamodel.LdaModel(构建主题模型)4lda.print_topics(打印主题).
1.dictionary = gensim.corpora.Dictionary(clean_content) 对输入的列表做一个数字映射字典, 2. corpus = [dictionary,do ...