- (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快速迭代的更多相关文章

  1. OC 线程操作 - GCD队列组

    1.队列组两种使用方法2.队列组等待 wait /** 新方法 队列组一般用在在异步操作,在主线程写队列组毫无任何作用 */ - (void)GCD_Group_new_group___notify{ ...

  2. OC 线程操作 - GCD使用 -同步函数,异步函数,串行队列,并发队列

    - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ // GCD 开几条线程并不是我们 ...

  3. OC 线程操作 - GCD使用 -线程通讯, 延迟函数和一次性代码

    - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ // [self downImag ...

  4. OC线程操作-GCD介绍

    1. GCD介绍 1.11.2 1.3 异步具备开启能力但是不是 一定可以开启 1.4 1.5 67. 8.

  5. OC 线程操作 - GCD使用 - 栅栏函数

    - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ //同步函数无需栅栏函数 //栅栏 ...

  6. OC 线程操作2 - NSThread

        方法1 :直接创建 alloc init - (void)createNSThread111{ /* 参数1: (nonnull id) 目标对象 self 参数2:(nonnull SEL) ...

  7. OC 线程操作3 - NSOperation

    #import "ViewController.h" @interface ViewController () @end @implementation ViewControlle ...

  8. OC 线程操作1 - pthread

    #import "ViewController.h" #import <pthread.h> //1.需要包含这个头文件 @interface ViewControll ...

  9. OC 线程操作3 - NSOperation 实现线程间通信

    #import "ViewController.h" @interface ViewController () /** 图片 */ @property (weak, nonatom ...

随机推荐

  1. fiddler基础功能介绍

  2. Sqoop+mysql+Hive+ Ozzie数据仓库案例

    mysql 数据库脚本为: /*==============================================================*/ /* DBMS name: MySQL ...

  3. Eclipse变量名自动补全问题 自定义上屏按键为TAB

    Eclipse空格等号等都可以上屏,这样有时候输入变量名再按空格就会自动补全,非常讨厌.那么怎么办呢? 1.首先你的Eclipse需要装有 Eclipse plug-in development en ...

  4. 怎么理解Linux软中断?

    1.什么是中断 中断是系统用来响应硬件设备请求的一种机制,它会打断进程的正常调度和执行,然后调用内核中的中断处理程序来响应设备的请求. 2.为什么要有中断呢? "举个生活中的例子" ...

  5. HTML5 Canvas ( 事件交互, 点击事件为例 ) isPointInPath

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  6. leetcode459

    public class Solution { public bool RepeatedSubstringPattern(string s) { var len = s.Length; ) { ret ...

  7. leetcode191

    public class Solution { public int HammingWeight(uint n) { var list = new List<uint>(); do { ; ...

  8. linux的基础

    vmtools 的安装:作用 ——>共享linux和windows的文件夹 reboot 重启 远程登录 : 远程登录时要打开sshd(监视22端口) 怎么设施sshd: 打开远端,输入setu ...

  9. thymeleaf的使用

    1.导包 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>sp ...

  10. vue-cli 上手

    1.cnpm install --global vue-cli 安装脚手架 2.vue init webpack baoge 创建 3.选择配置项 Project name (baoge): ---- ...