Waiting on Groups of Queued Tasks
https://developer.apple.com/library/content/documentation/General/Conceptual/ConcurrencyProgrammingGuide/OperationQueues/OperationQueues.html#//apple_ref/doc/uid/TP40008091-CH102-SW25
Waiting on Groups of Queued Tasks
Dispatch groups are a way to block a thread until one or more tasks finish executing. You can use this behavior in places where you cannot make progress until all of the specified tasks are complete. For example, after dispatching several tasks to compute some data, you might use a group to wait on those tasks and then process the results when they are done. Another way to use dispatch groups is as an alternative to thread joins. Instead of starting several child threads and then joining with each of them, you could add the corresponding tasks to a dispatch group and wait on the entire group.
Listing 3-6 shows the basic process for setting up a group, dispatching tasks to it, and waiting on the results. Instead of dispatching tasks to a queue using the dispatch_async
function, you use the dispatch_group_async
function instead. This function associates the task with the group and queues it for execution. To wait on a group of tasks to finish, you then use the dispatch_group_wait
function, passing in the appropriate group.
Listing 3-6 Waiting on asynchronous tasks
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); |
dispatch_group_t group = dispatch_group_create(); |
// Add a task to the group |
dispatch_group_async(group, queue, ^{ |
// Some asynchronous work |
}); |
// Do some other work while the tasks execute. |
// When you cannot make any more forward progress, |
// wait on the group to block the current thread. |
dispatch_group_wait(group, DISPATCH_TIME_FOREVER); |
// Release the group when it is no longer needed. |
dispatch_release(group); |
Waiting on Groups of Queued Tasks的更多相关文章
- Java theory and practice: Thread pools and work queues--reference
Why thread pools? Many server applications, such as Web servers, database servers, file servers, or ...
- async源码学习 - 全部源码
因为工作需要,可能我离前端走远了,偏node方向了.所以异步编程的需求很多,于是乎,不得不带着学习async了. 我有个习惯,用别人的东西之前,喜欢稍微搞明白点,so就带着看看其源码. github: ...
- Async Performance: Understanding the Costs of Async and Await
Stephen Toub Download the Code Sample Asynchronous programming has long been the realm of only the m ...
- jdk8中java.util.concurrent包分析
并发框架分类 1. Executor相关类 Interfaces. Executor is a simple standardized interface for defining custom th ...
- java.util.concurrent包详细分析--转
原文地址:http://blog.csdn.net/windsunmoon/article/details/36903901 概述 Java.util.concurrent 包含许多线程安全.测试良好 ...
- java多线程系类:JUC线程池:03之线程池原理(二)(转)
概要 在前面一章"Java多线程系列--"JUC线程池"02之 线程池原理(一)"中介绍了线程池的数据结构,本章会通过分析线程池的源码,对线程池进行说明.内容包 ...
- Java多线程系列--“JUC线程池”03之 线程池原理(二)
概要 在前面一章"Java多线程系列--“JUC线程池”02之 线程池原理(一)"中介绍了线程池的数据结构,本章会通过分析线程池的源码,对线程池进行说明.内容包括:线程池示例参考代 ...
- [python学习笔记]Day2
摘要: 对象 对于python来说,一切事物都是对象,对象基于类创建: 注:查看对象相关成员 var,type,dir 基本数据类型和序列 int内部功能 class int(object): def ...
- ThreadPoolExecutor(转)
让ThreadPoolExecutor的workQueue占满时自动阻塞submit()方法 By learnhard | 2015 年 09 月 04 日 0 Comment 转载请注明出处:htt ...
随机推荐
- SQL异常捕获
直接上代码: GO BEGIN TRY DECLARE @res INT SET @res=1/0 PRINT 'no error' END TRY BEGIN CATCH PRINT 'Error ...
- echarts Y轴数据类型不同怎么让折线图显示差距不大
如果希望在同一grid中展示不同数据类型的折线(1000或10%),那么展现出来的折线肯定显示差距很大,那么怎么让这两条折线显示效果差不多,在之前的项目中碰到了这个问题 每条折线对应的是不同的数据组, ...
- RabbitMQ原理——exchange、route、queue的关系
从AMQP协议可以看出,MessageQueue.Exchange和Binding构成了AMQP协议的核心,下面我们就围绕这三个主要组件 从应用使用的角度全面的介绍如何利用Rabbit MQ构建 ...
- dockerfile 语法
基本语法格式:INSTRUCTION arguments (指令+参数)不分大小写 注释格式:# 注释 第一个指令必须是FROM,标示使用什么镜像 1.解析器指令 解析器指令是可选的,并且影响处理Do ...
- windows 系统 python3.5安装 lxml 库
有个提示uable find vc***,的错误,如果按照修改python脚本的方法会发现还需要安装VS,安装好了还不一定可以解决问题. 费了半天劲,结合网络上部分信息终于找到了解决方案: 1.打开文 ...
- Oracle 基础系列之1.3 用户管理
一.概述 1.当我们使用sysdba创建一个新用户时,该用户是没有任何权限的,甚至连登录数据库的权限都没有,代码如下: 这里使用sysdba创建了一个用户名为'zc'的新用户,接着输入代码进行登录 e ...
- (Frontend Newbie)JavaScript基础之常见数据类型
JavaScript中的数据类型分为两种,一种是简单数据类型,包括Undefined.Null.Boolean.Number和String,另一种是复杂数据类型,即Object,也可称作为引用类型. ...
- 1、java线程模型
要了解多线程,先需要把java线程模型搞清楚,否则有时候很难理清楚一个问题. 硬件多线程: 物理机硬件的并发问题跟jvm中的情况有不少相似之处,物理机的并发处理方案对于虚拟机也有相当大的参考意义.在买 ...
- pat02-线性结构2. 一元多项式求导 (25)
02-线性结构2. 一元多项式求导 (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 设计函数求一元多项式的导数.(注:xn(n为整 ...
- 存储型xss调研
概念 存储型XSS,持久化,代码是存储在服务器中的,如在个人信息或发表文章等地方,加入代码,如果没有过滤或过滤不严,那么这些代码将储存到服务器中,用户访问该页面的时候触发代码执行. 常见的xss攻击方 ...