Concurrency Programming Guide 并发设计指引(一)

8 篇文章 0 订阅

以下翻译是本人通过谷歌工具进行翻译,并进行修正后的结果,希望能对大家有所帮助。如果您发现翻译的不正确不合适的地方,希望您能够发表评论指正,谢谢。转载请注明出处。

Introduction
简介

Concurrency is the notion of multiple things happening at the same time. With the proliferation of multicore CPUs and the realization that the number of cores in each processor will only increase, software developers need new ways to take advantage of them. Although operating systems like OS X and iOS are capable of running multiple programs in parallel, most of those programs run in the background and perform tasks that require little continuous processor time. It is the current foreground application that both captures the user’s attention and keeps the computer busy. If an application has a lot of work to do but keeps only a fraction of the available cores occupied, those extra processing resources are wasted.

并发表示同时发生多件事情的概念。随着多核CPU和实现,在每个处理器的内核数量只会增加扩散,软件开发商需要新的方式来利用它们。虽然像OS X和IOS这样的操作系统能够用并行的运行多个程序,但是大多数的程序运行在后台,然后执行需要很少连续时间的任务。当前的前台的程序吸引了用户的注意力,而且使得处理器一直繁忙。如果一个程序有许多的事情要做但是只能使多个芯片的一小部门可用的,那么这些额外的芯片资源就被浪费掉了。

In the past, introducing concurrency to an application required the creation of one or more additional threads. Unfortunately, writing threaded code is challenging. Threads are a low-level tool that must be managed manually. Given that the optimal number of threads for an application can change dynamically based on the current system load and the underlying hardware, implementing a correct threading solution becomes extremely difficult, if not impossible to achieve. In addition, the synchronization mechanisms typically used with threads add complexity and risk to software designs without any guarantees of improved performance.

在过去,向一个程序中引入并发需要创建一个活多个额外的线程。不幸的是书写线程代码是一种挑战。线程是一种需要手动管理的低级别的工具。鉴于目前的系统负载和底层硬件,应用程序的最佳线程数可以动态变化,实施正确的线程解决方案变得非常困难,但不是不可能实现的。此外,通常使用的线程的同步机制增加加了软件设计的复杂性和风险性,风险就是性能改进可能得不到任何保障


Both OS X and iOS adopt a more asynchronous approach to the execution of concurrent tasks than is traditionally found in thread-based systems and applications. Rather than creating threads directly, applications need only define specific tasks and then let the system perform them. By letting the system manage the threads, applications gain a level of scalability not possible with raw threads. Application developers also gain a simpler and more efficient programming model.
OS X和iOS采用更多的异步方法去执行并发的应用程序,而不是在传统的基于线程的系统和应用程序里面去寻找。比起直接去创建线程,应用程序只需要定义特定的任务,然后让系统去执行他们。通过让系统管理线程,不需要对线程进行加工,应用就能够获得更高的扩展性。应用的开发者也能够获得一种简单和更有效的编程模型。


This document describes the technique and technologies you should be using to implement concurrency in your applications. The technologies described in this document are available in both OS X and iOS.
这篇文档描述你需要在你的应用中用到的技巧和技术去运行并发。这些文档中描述的技术在OS X和IOS中都是可供使用的。

Organization of This Document
文档结构

This document contains the following chapters:
文档包括如下章节:
“Concurrency and Application Design” introduces the basics of asynchronous application design and the technologies for performing your custom tasks asynchronously.
“Operation Queues” shows you how to encapsulate and perform tasks using Objective-C objects.
“Dispatch Queues” shows you how to execute tasks concurrently in C-based applications.
“Dispatch Sources” shows you how to handle system events asynchronously.
“Migrating Away from Threads” provides tips and techniques for migrating your existing thread-based code over to use newer technologies.

1.“Concurrency and Application Design”介绍了基本的异步应用设计和技术去运行你的常见的异步任务。

2. “Operation Queues”显示了如何去封装和执行任务用OC 对象。
3. “Dipatch Queues”显示了如何去兼容性的执行基于C的应用
4. “Dipatch Sources”显示如何异步去处理系统事件
5. “Migrating Away from  Threads”提供了方法和技术帮助你把已经存在的基于线程的代码迁移到新的技术上。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值