Also known as multi-threaded programming concurrent programming because of its large role, there are more theoretical knowledge, so the interview is also favored by the interviewer. In everyday project development, at least on network requests is the need to use multiple threads of knowledge, although the use of third-party frameworks such as AFNetworking network request is relatively simple, but also requires the developer to have a clearer idea of multi-threading, block and other knowledge in order in the face of problems can be structured to identify and solve problems.
Positioning of this article is combing the iOS development multithreading knowledge, can be considered an outline, one can learn or review multithreading knowledge when there is a guide, and secondly, can also be used as a multi-threaded own knowledge tested to see if they can according to the outline, do fine processing.
In iOS development, I think mainly three aspects of the knowledge to be very clear:
(A) multi-thread-related knowledge
(B) GCD of use
(C) NSOperation use
First of all, the multi-thread-related knowledge
(A) the relationship between the three: processes, threads, tasks
(B) the introduction of multi-threading technology: concepts, principles, advantages and disadvantages, application scenarios
Task execution (three) thread is a serial
(Iv) multi-threading technology: pthread, NSThread, GCD, NSOperation
Related operations (five) thread: create, start, running, blocking, destruction
Inter-related operations (6) threads: data sharing, communication between threads
(Vii) related terms on threads: the main thread, the child thread
Then, GCD of use
(A) There are two concepts need to be clear in the GCD: function queue
(B) the two types of functions: synchronous function - perform tasks in the current thread does not have the ability to open a new thread
Asynchronous function - perform tasks in the new thread, the ability to open a new thread
(C) two kinds of queues: queue Serial - a task execution after completion, and then perform the next task
Concurrent queue - multiple tasks simultaneously
(D) three queue Example: main queue, the queue from the serial creating global concurrent queue
(E) formula is: add tasks to the queue with ______ ______ function.
Is a combination of six cases:
Synchronous function, to the main queue, add tasks - not open a new thread, serial tasks ( in this way will form an infinite loop! )
Synchronous function to create a serial from the queue, add tasks - not open a new thread, serial mission
Synchronous function, to the global concurrent queue, add tasks - not open a new thread, serial mission
Asynchronous function, to the main queue and add tasks - not open a new thread, serial mission
Asynchronous function to create a serial from the queue, add tasks - have opened a new thread, serial mission
Asynchronous function, to the global concurrent queue, add tasks - have opened a new thread, concurrent execution of tasks ( this is the way to play GCD performance! )
Communication between the (six) threads: threads from the child back to the main thread to perform tasks
(Vii) the GCD usual manner: delayed execution, is performed once, using a queue group
Finally, NSOperation use