iOS is multi-threaded and involves some of the following classes, which are concentrated here to avoid confusion.
1, Nstimer
Obviously, this is the timer class.
2, Nstask
IOS does not support Nstask
In many concurrent operations, multithreading is too resource-intensive, too dangerous, when many processes come out, through the Nstask can invoke external executable program
3, Nsthread
IOS supports multiple levels of multithreaded programming, the higher the level of abstraction, the more convenient to use, but also Apple's most recommended method.
The following is a list of the multithreaded programming paradigms supported by IOS, from low to high, based on the level of abstraction:
1. Thread;
2. Cocoa operations;
3. Grand Central Dispatch (GCD) (iOS4 only starts to support)
The following is a brief description of these three different paradigms:
Thread is relatively lightweight in these three paradigms, but is also the most responsible for the use, you need to manage the thread's life cycle, synchronization between threads.
Threads share part of the memory space of the same application, and they have the same access rights to the data. You have to coordinate the access of multiple threads to the same data, and the general practice is to lock them before access, which can lead to some performance overhead.
In IOS we can use multiple forms of Thread:cocoa threads: using Nsthread or directly from the NSObject class method Performselectorinbackground:withobject: To create a thread.
If you choose thread to implement multi-threading, then nsthread is the preferred way to use the official recommendation.
POSIX Threads: A multi-line libraries based on the C language, Cocoa operations is based on Obective-c, and Nsoperation encapsulates the class operations that the user needs to perform in an object-oriented manner, and we just focus on what we need to do, Instead of worrying too much about threading management, syncing, and so on, because Nsoperation has encapsulated these things for us.
Nsoperation is an abstract base class, and we must use its subclasses. Two default implementations of IOS are available: Nsinvocationoperation and nsblockoperation.
Grand Central Dispatch (GCD): IOS4 only started to support, it provides some new features, and the runtime to support multicore parallel programming, with a higher focus: how to increase efficiency on multiple CPUs.
With the overall framework above, we can clearly know the level of different ways and the possible efficiency, convenience differences.
4, Nsrunloop
Nsrunloop essence is a processing mode of message mechanism
All "messages" are added to the Nsrunloop, where the messages are divided into "input source" and "Timer source"
And check in the loop whether there are events that need to happen, and then call the appropriate function processing if necessary.
5, Nsoperation
A beautiful abstract task, with a subclass operation object that comes from the definition. Inheriting nsoperation can fully control the implementation of the Operation object, including how to modify operation execution and status reporting.
6, Nsoperationqueue
The task submitted to Operation queues must be a Nsoperation object, and Operation object encapsulates the work you want to do, along with all the data you need.
Since Nsoperation is an abstract base class, you typically need to define custom subclasses to perform tasks. But the foundation framework comes with some specific subclasses that you can create and perform related tasks.
A Nsoperationqueue action queue, which is the equivalent of a thread manager, not a thread. Because you can set the number of threads that can run in parallel in this thread manager, and so on.
7, Nsinvocationoperation
You can use the class directly, based on an applied object and selector to create the Operation object. If you already have an existing method to perform the required tasks, you can use this class.
8, Nsblockoperation
A class that can be used directly to execute one or more block objects concurrently. Operation Object uses the semantics of "group" to execute multiple block objects, and operation object is completed after all the relevant blocks have been executed.
iOS Multithreading common class description--Alternate reference