This article is mainly my summary of multithreading, when it is a review for their own, but also to others some reference.
or from a simple beginning, first introduce some conceptual things, although simple, but the depth of understanding determines whether the use of multi-threaded, but also useful how good.
Threads: A thread is a single sequential control flow in a program, an entity in a thread, a standard thread consisting of a thread ID, a current instruction pointer (PC), a collection of registers, and a stack .
It has the following properties:
1, light entities. 2, the basic unit of independent Dispatch and dispatch. 3, can be executed concurrently. 4. Share process resources.
The next step is to use the four multithreaded programming options available in iOS:
(a) Pthread
Here is not very detailed to explain it, Baidu said:
The POSIX thread (POSIX threads), referred to as pthreads, is the POSIX standard for threading. The standard defines a complete set of APIs for creating and manipulating threads. In Unix-like operating systems (Unix, Linux, Mac OS x, and so on), pthreads is used as the operating system thread. The Windows operating system also has its ported version of Pthreads-win32.
It is rarely used directly in iOS development. To use it you have to use a series of C interfaces in Pthread.h, using those underlying interfaces to create, schedule, and manage threads, which are relatively complex and have many problems to consider.
Two Nsthread
It is Apple's further encapsulation of pthread and is object-oriented. After encapsulation we face the thread object, and its interface is better understood, more intuitive and convenient to use.
Three Grand Central Dispatch (GCD).
It is a solution to the multi-core programming developed by Apple. Using GCD, it automatically manages the thread's life cycle (creating threads, scheduling tasks, destroying threads), does not require our management at all, we focus on the focus as long as it is in its own task, and puts the task into the appropriate queue. The use of GCD c语言 , combined with Block, makes it more convenient and flexible to use.
(d) nsoperation
Nsoperation is also a basic CGD package after iOS 4.x, it is a CGD object-oriented package, and provides useful and thread-safe establishment status, priority, dependency, and cancellation operations.
IOS Multithreaded Development