1.队列组两种使用方法
2.队列组等待 wait

/** 新方法
队列组一般用在在异步操作,在主线程写队列组毫无任何作用
*/
- (void)GCD_Group_new_group___notify{
dispatch_queue_t queue = dispatch_queue_create("11", DISPATCH_QUEUE_CONCURRENT);
dispatch_queue_t globalqueue = dispatch_get_global_queue(0, 0);
dispatch_group_t group = dispatch_group_create();
/*
1.封装任务
2.把任务加到队列
3.会监听任务的执行情况
*/
dispatch_group_async(group, globalqueue, ^{
NSLog(@"1111---%@---", [NSThread currentThread]);
}); dispatch_group_async(group, globalqueue, ^{
NSLog(@"22222---%@---", [NSThread currentThread]);
}); dispatch_group_async(group, globalqueue, ^{
NSLog(@"333---%@---", [NSThread currentThread]);
}); // 一定要加上这行,不然不起任何作用
dispatch_group_notify(group, globalqueue, ^{
NSLog(@"完成----4444---%@---", [NSThread currentThread]);
}); /*
打印结果:
2018-06-28 10:18:44.191407+0800 5线程操作-GCD-快速迭代[7808:56262] 333---<NSThread: 0x6000002682c0>{number = 4, name = (null)}---
2018-06-28 10:18:44.191409+0800 5线程操作-GCD-快速迭代[7808:56266] 1111---<NSThread: 0x608000075300>{number = 3, name = (null)}---
2018-06-28 10:18:44.191434+0800 5线程操作-GCD-快速迭代[7808:56264] 22222---<NSThread: 0x600000266580>{number = 5, name = (null)}---
2018-06-28 10:18:44.191758+0800 5线程操作-GCD-快速迭代[7808:56264] 完成----4444---<NSThread: 0x600000266580>{number = 5, name = (null)}---
*/
    //DISPATCH_TIME_FOREVER :等待队列所有任务执行完后 执行下面代码后面的内容
dispatch_group_wait(group, DISPATCH_TIME_FOREVER);
NSLog(@"执行完了");
/*
打印结果:
2018-06-28 10:58:34.631990+0800 5线程操作-GCD-快速迭代[8500:86081] 1111---<NSThread: 0x60400007e180>{number = 3, name = (null)}---
2018-06-28 10:58:34.632041+0800 5线程操作-GCD-快速迭代[8500:86084] 22222---<NSThread: 0x60400007e4c0>{number = 4, name = (null)}---
2018-06-28 10:58:34.632065+0800 5线程操作-GCD-快速迭代[8500:86080] 333---<NSThread: 0x60400007e380>{number = 5, name = (null)}---
2018-06-28 10:58:34.633261+0800 5线程操作-GCD-快速迭代[8500:86052] 执行完了
2018-06-28 10:58:34.633284+0800 5线程操作-GCD-快速迭代[8500:86080] 完成----4444---<NSThread: 0x60400007e380>{number = 5, name = (null)}---
*/
}
//老式写法
- (void)GCD_GroupDemo_old___enter_leave{
dispatch_queue_t queue = dispatch_queue_create("", DISPATCH_QUEUE_CONCURRENT);
dispatch_queue_t globalqueue = dispatch_get_global_queue(, );
dispatch_group_t group = dispatch_group_create();
dispatch_group_enter(group); // 旧 写法
dispatch_group_async(group, globalqueue, ^{
NSLog(@"离开---%@---", [NSThread currentThread]);
dispatch_group_leave(group);
});
dispatch_group_async(group, globalqueue, ^{
NSLog(@"222---%@---", [NSThread currentThread]);
});
dispatch_group_async(group, globalqueue, ^{
NSLog(@"333---%@---", [NSThread currentThread]);
}); dispatch_group_async(group, globalqueue, ^{
NSLog(@"111---%@---", [NSThread currentThread]);
});
/*
2018-06-28 10:25:06.997243+0800 5线程操作-GCD-快速迭代[7942:62493] 离开---<NSThread: 0x60c00007f8c0>{number = 3, name = (null)}---
2018-06-28 10:25:06.997286+0800 5线程操作-GCD-快速迭代[7942:62491] 333---<NSThread: 0x60800007d240>{number = 5, name = (null)}---
2018-06-28 10:25:06.997306+0800 5线程操作-GCD-快速迭代[7942:62489] 111---<NSThread: 0x608000260c80>{number = 6, name = (null)}---
2018-06-28 10:25:06.997287+0800 5线程操作-GCD-快速迭代[7942:62492] 222---<NSThread: 0x60c00007de40>{number = 4, name = (null)}---
*/
}

OC 线程操作 - GCD队列组的更多相关文章

  1. OC 线程操作 - GCD快速迭代

    - (void)forDemo{ //全都是在主线程操作的 ; i<; i++) { NSLog(@"--%@", [NSThread currentThread]); } ...

  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使用 - 栅栏函数

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

  5. OC线程操作-GCD介绍

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

  6. iOS边练边学--GCD的基本使用、GCD各种队列、GCD线程间通信、GCD常用函数、GCD迭代以及GCD队列组

    一.GCD的基本使用 <1>GCD简介 什么是GCD 全称是Grand Central Dispatch,可译为“牛逼的中枢调度器” 纯C语言,提供了非常多强大的函数   GCD的优势 G ...

  7. 多线程 GCD队列组

    //  DYFViewController.m //  623-08-队列组 // //  Created by dyf on 14-6-23. //  Copyright (c) 2014年 ___ ...

  8. OC 线程操作2 - NSThread

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

  9. OC - GCD 队列组 - 下载图片画图

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

随机推荐

  1. python3 钉钉群机器人 webhook

    import requests import json url='https://oapi.dingtalk.com/robot/send?access_token=替换成你自己的toten' pro ...

  2. direct path read/write (直接路径读/写)

    转载:http://www.dbtan.com/2010/04/direct-path-readwrite.html direct path read/write (直接路径读/写): 直接路径读(d ...

  3. 原生socket请求url获取状态码、消息报头、响应正文

    需求: (1)使用socket及ssl模块写通用的web客户端 (2)向服务器发起请求 (3)接受响应内容并解析出状态码.消息报头.响应正文 (4)最核心的函数: 输入一个url,返回状态码.消息报头 ...

  4. 进程之间的数据共享 -----Manager模块

    展望未来,基于消息传递的并发编程是大势所趋 即便是使用线程,推荐做法也是将程序设计为大量独立的线程集合,通过消息队列交换数据. 这样极大地减少了对使用锁定和其他同步手段的需求,还可以扩展到分布式系统中 ...

  5. controller检查header

    以前都只能拿到request再检查,其实有相应的注解. public Result updateRecentScore(@RequestBody Map map, @RequestHeader(&qu ...

  6. class(类的使用说明)

    class 的三大特性 封装:内部调用对于外部用户是透明的 继承: 在分类里的属性,方法被自动继承 多态:调用这个功能,可以使多个类同时执行 r1 = Role(r1, 'Alex', 'Police ...

  7. websocket使用

    兼容性介绍 : https://caniuse.com/#search=websockets var websocket = null; //判断当前浏览器是否支持WebSocket if ('Web ...

  8. mongodb基础学习13-聚集aggregate操作

    aggregate可以用的操作与sql的对应关系 下面来看具体操作例子: 分组求和: 求总记录数 商品价格大于50记录分组求和 商品价格大于50且分组记录大于2的分组记录条件 分组库存数,并按库存排序 ...

  9. (1)shiro简介和第一个demo

    之前一直在用shiro开发,不过只是会使用,并没有深入了解,最近有时间学习了一下,把最近学习所得分享一下. shiro简介 Apache Shiro是一个强大且易用的Java安全框架,执行身份验证.授 ...

  10. 【348】通过 Numpy 创建各式各样的矩阵

    参考:NumPy之array-一个程序媛的自我修养-51CTO博客 参考:numpy中数组和矩阵的区别 - jiangsujiangjiang的博客 - CSDN博客 一.使用系统方法 二.用指定的数 ...