OC 线程操作 - GCD队列组
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队列组的更多相关文章
- OC 线程操作 - GCD快速迭代
- (void)forDemo{ //全都是在主线程操作的 ; i<; i++) { NSLog(@"--%@", [NSThread currentThread]); } ...
- 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使用 - 栅栏函数
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ //同步函数无需栅栏函数 //栅栏 ...
- OC线程操作-GCD介绍
1. GCD介绍 1.11.2 1.3 异步具备开启能力但是不是 一定可以开启 1.4 1.5 67. 8.
- iOS边练边学--GCD的基本使用、GCD各种队列、GCD线程间通信、GCD常用函数、GCD迭代以及GCD队列组
一.GCD的基本使用 <1>GCD简介 什么是GCD 全称是Grand Central Dispatch,可译为“牛逼的中枢调度器” 纯C语言,提供了非常多强大的函数 GCD的优势 G ...
- 多线程 GCD队列组
// DYFViewController.m // 623-08-队列组 // // Created by dyf on 14-6-23. // Copyright (c) 2014年 ___ ...
- OC 线程操作2 - NSThread
方法1 :直接创建 alloc init - (void)createNSThread111{ /* 参数1: (nonnull id) 目标对象 self 参数2:(nonnull SEL) ...
- OC - GCD 队列组 - 下载图片画图
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ [self downloadIma ...
随机推荐
- win7连接centos的nfs
nfs的服务端这边设置忽略. 主要关于权限的问题: Windows7 NFS客户端,使用mount命令挂载NFS服务之后,文件系统对Win7只读,无法写入文件,无法新建文件夹解决方法. 在win的cm ...
- echo off
就是说关闭回显 @echo off并不是DOS程序中的,而是DOS批处理中的.当年的DOS,所有操作都用键盘命令来完成,当你每次都要输入相同的命令时,可以把这么多命令存为一个批处理,从此以后,只要运行 ...
- Game of War - Fire Age 有何特别之处?
作者:福克斯007 链接:https://www.zhihu.com/question/21611550/answer/52458767来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转 ...
- 解决Sublime 3提示 Sublime Text Error while loading PyV8 binary
转自:http://blog.initm.com/sublime-text/ 今天打开sublime遇到一个提示 如上图Sublime Text Error while loading PyV8 b ...
- HTC Vive的定位技术
Lighthouse空间定位,chaperone系统避免实际障碍物 HTC vive所用的Lighthouse技术属于激光定位技术,Oculus Rift以及索尼PlayStation VR所用的定位 ...
- java编译器
编译: .java变成.class 前端编译 Sun javac Eclipse ECJ .class变成机器码 运行期编译 等HostSpot VM c1,c2 .jav ...
- 图文并茂 RAID 技术全解 – RAID0、RAID1、RAID5、RAID100
RAID 技术相信大家都有接触过,尤其是服务器运维人员,RAID 概念很多,有时候会概念混淆.这篇文章为网络转载,写得相当不错,它对 RAID 技术的概念特征.基本原理.关键技术.各种等级和发展现状进 ...
- CYQ.Data 数据框架 使用篇一 入门指南---001
原文链接:http://www.cyqdata.com/cyqdata/article-detail-411 本文针对V5版本进行修改于(2016-07-04) 下面是使用步骤: 一:下载框架DLL[ ...
- [Dart] Flutter 上传文件
/** * 请求响应数据 */ class MsgResponse { int code; // 状态代码,0 表示没有错误 Object data; // 数据内容,一般为字符串 String er ...
- 2k8 32bit下载
Windows Server 2008 32-bit Standard(标准版) Windows Server 2008 32-bit Enterprise(企业版) Windows Server 2 ...