IOS 多線程編程指南:1介紹

Introduction


Threads are one of several technologies that make it possible to execute multiple code paths concurrently inside a single application. Although newer technologies such as operation objects and Grand Central Dispatch (GCD) provide a more modern and efficient infrastructure for implementing concurrency, OS X and iOS also provide interfaces for creating and managing threads.

This document provides an introduction to the thread packages available in OS X and shows you how to use them. This document also describes the relevant technologies provided to support threading and the synchronization of multithreaded code inside your application.

Important: If you are developing a new application, you are encouraged to investigate the alternative OS X technologies for implementing concurrency. This is especially true if you are not already familiar with the design techniques needed to implement a threaded application. These alternative technologies simplify the amount of work you have to do to implement concurrent paths of execution and offer much better performance than traditional threads. For information about these technologies, see Concurrency Programming Guide.

簡介


線程是一種技術,這種技術可以在單個應用中同時執行多個路徑的代碼。雖然新技術如對象操作和Grand Central Dispatch(GCD)提供了更現代、高效的並實現併發的方式,OS X和iOS依然提供的接口來創建和管理線程。

本文檔提供了在OSX中包含的線程包的介紹,並向展示瞭如何使用它們。本文檔還介紹了支持線程的相關技術,以及應用程序中實現多線程代碼的同步。

重要提示:如果你正在開發一個新的應用程序,建議你被去研究其他OSX應用程序實現併發的技術。這一點挺重要,如果你還不熟悉設計一個多線程應用所需的技術。這些替代技術簡化了你實現併發的工作量,並且提供了比傳統的線程更好的性能。有關這些技術的信息,請參見併發編程指南《Concurrency Programming Guide》。

Organization of This Document


This document has the following chapters and appendixes:

  • About Threaded Programming introduces the concept of threads and their role in application design.
  • Thread Management provides information about the threading technologies in OS X and how you use them.
  • Run Loops provides information about how to manage event-processing loops in secondary threads.
  • Synchronization describes synchronization issues and the tools you use to prevent multiple threads from corrupting data or crashing your program.

文檔的組織


文檔有以下章節和附錄:

  • About Threaded Programming 介紹線程的概念及其在應用程序設計中的作用。
  • Thread Management 線程管理提供了OSX中線程技術以及如何使用它們的信息。
  • Run Loops 提供了關於如何管理二次線程中的事件處理循環的信息。
  • Synchronization 同步描述的同步問題,和如何使用你的工具來防止多線程中數據的破壞或程序崩潰。
  • Thread Safety Summary 線程安全總結 提供了iOS和OS X和一些主要框架固有的線程安全的高度概括的總結。

See Also


For information about the alternatives to threads, see Concurrency Programming Guide.

This document provides only a light coverage of the use of the POSIX threads API. For more information about the available POSIX thread routines, see the pthread man page. For a more in-depth explanation of POSIX threads and their usage, see Programming with POSIX Threads by David R. Butenhof.

另見


更多關於其他線程技術的信息,請看: Concurrency Programming Guide(同步編程指南).

本文檔僅僅提供了POSIX線程API的使用概述。有關可用的POSIX線程程序的更多信息,參見 pthread man page。更多POSIX線程使用的解釋,參見戴維R. butenhof POSIX多線程編程。參見David R. Butenhof寫的 Programming with POSIX Threads。

發佈了92 篇原創文章 · 獲贊 137 · 訪問量 19萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章