美文网首页
01. Concurrency Programming Guid

01. Concurrency Programming Guid

作者: ngugg | 来源:发表于2018-11-01 15:11 被阅读6次

相关链接: https://developer.apple.com/library/archive/documentation/General/Conceptual/ConcurrencyProgrammingGuide/Introduction/Introduction.html

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.

    • Operation Queues向您展示如何使用Objective-C对象封装和执行任务。
  • Dispatch Queues shows you how to execute tasks concurrently in C-based applications.

    • Dispatch Queues向您展示如何在基于C的应用程序中同时执行任务。
  • Dispatch Sources shows you how to handle system events asynchronously.

    • Dispatch Sources向您展示了如何异步处理系统事件。
  • Migrating Away from Threads provides tips and techniques for migrating your existing thread-based code over to use newer technologies.

    • 迁移远离线程提供了有关迁移现有基于线程的代码以使用新技术的提示和技巧。

This document also includes a glossary that defines relevant terms.

  • 本文档还包括定义相关术语的术语表。

A Note About Terminology

  • 关于术语的注释

Before entering into a discussion about concurrency, it is necessary to define some relevant terminology to prevent confusion. Developers who are more familiar with UNIX systems or older OS X technologies may find the terms “task”, “process”, and “thread” used somewhat differently in this document. This document uses these terms in the following way:

  • 在进行关于并发性的讨论之前,有必要定义一些相关的术语以防止混淆。 更熟悉UNIX系统或旧OS X技术的开发人员可能会发现本文档中使用的术语“任务”,“进程”和“线程”略有不同。 本文档以下列方式使用这些术语:
  • The term thread is used to refer to a separate path of execution for code. The underlying implementation for threads in OS X is based on the POSIX threads API.
  • 术语 thread *用于指代代码的单独执行路径。 OS X中线程的底层实现基于POSIX线程API。
  • The term process is used to refer to a running executable, which can encompass multiple threads.
  • 术语 process *用于表示正在运行的可执行文件,它可以包含多个线程。
  • The term task is used to refer to the abstract concept of work that needs to be performed.
  • 术语任务*用于指代需要执行的抽象工作概念。

For complete definitions of these and other key terms used by this document, see Glossary.

  • 有关本文档使用的这些和其他关键术语的完整定义,请参阅[术语表]

See Also

This document focuses on the preferred technologies for implementing concurrency in your applications and does not cover the use of threads. If you need information about using threads and other thread-related technologies, see Threading Programming Guide.

  • 本文档重点介绍在应用程序中实现并发的首选技术,但不涉及线程的使用。 如果您需要有关使用线程和其他线程相关技术的信息,请参阅* [线程编程指南]

相关文章

网友评论

      本文标题:01. Concurrency Programming Guid

      本文链接:https://www.haomeiwen.com/subject/xthgtqtx.html