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 ...
随机推荐
- 6.27-JSTL、标签、分页
一.JSTL 条件标签: <c:if> if if(){ }else if(){ }else{ } <c:choose> <c:when></c:when&g ...
- Python的collections模块中namedtuple结构使用示例
namedtuple顾名思义,就是名字+元组的数据结构,下面就来看一下Python的collections模块中namedtuple结构使用示例 namedtuple 就是命名的 tuple,比较 ...
- Oracle 存储过程 延迟执行 DBMS_LOCK.SLEEP(60);
--测试代码: declare -- Local variables here i integer; begin -- Test statements here dbms_output.put_l ...
- 51. linux卸载jdk
看有的资料上说有些Linux自带的有jdk1.4:如果自带的有jdk1.4的话首先要把jdk1.4卸载掉.具体做法: 输入命令: #rpm -qa | grep gcj 如果输出没有内容,说明没有jd ...
- 加密算法之AES算法(转)
转载http://www.mamicode.com/info-detail-514466.html 0 AES简介 美国国家标准技术研究所在2001年发布了高级加密标准(AES).AES是一个对称分组 ...
- 2.mybatis实战教程(mybatis in action)之二:以接口的方式编程
转自:http://www.yihaomen.com/article/java/304.htm 前面一章,已经搭建好了eclipse,mybatis,mysql的环境,并且实现了一个简单的查询. 请注 ...
- 线程安全计算 AtomicLong
一般如果我们自己写一个计数器方法,需要考虑线程安全问题,尤其高并发访问的时候. AtomicLong 已处理并发问题,直接使用.java.util.concurrent.atomic包提供多种线程安全 ...
- JavaScript加法
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <hea ...
- 怎样在本地windows安装和配置zookeeper
Zookeeper是什么?有什么用? Zookeeper是一个分布式协调服务. 作用:为用户的分布式应用程序提供协调服务. zookeeper在底层其实只提供了两个功能: 1.管理(存储,读取)用户 ...
- Spring Boot @Trasactionl 失效, JDK,CGLIB动态代理
来自: https://www.cnblogs.com/sweetchildomine/p/6978037.html?utm_source=itdadao&utm_medium=referra ...