First, what is a thread:
1, a process to perform tasks, must have a thread (at least 1 threads per 1 processes)
2, the thread is the basic execution unit of the process, all tasks of a process (program) are executed in thread
3, 1 threads in the execution of the task is serial, if you want to perform multiple tasks in 1 threads, then you can only perform these tasks sequentially, that is, at the same time, 1 threads can only perform one task
Second, what is multi-threaded
1. Multiple threads can be opened in one process, each thread can perform different tasks in parallel (at the same time)
Example: Process--workshop, threading--workshop workers
2, the principle of multi-threading: The same time, the CPU can only handle 1 threads, only 1 threads in the work (execution), multi-threaded concurrency (at the same time) execution, its essence is the CPU quickly between the multi-thread scheduling (switching), when the CPU scheduler thread speed enough block, resulting in multi-threaded concurrent execution of the illusion
Third, what is the main thread
1. After an iOS program runs, 1 threads are turned on by default to become the main thread or UI thread
2. Main function: Display, refresh UI interface, handle UI events (such as click events, scrolling events, drag events, etc.)
3, use the main thread need to note: Do not put more time-consuming operations on the main thread, the card UI (blocking UI)
Iv. implementation of multi-threading in iOS
1, Pthread
Introduction: A set of generic threading API for Unix\linux\windows and other systems, cross-platform, portable, and difficult to use.
Language: C
Thread Life cycle: Programmer Management
Frequency of use: almost no
2, Nsthread
Summary: Use more object-oriented, easy-to-operate, direct manipulation of thread objects
Language: OC
Thread Life cycle: Programmer Management
Frequency of Use: occasional use
3, GCD
Introduction: Designed to replace threading technology such as Nsthread to take full advantage of device multicore
Introduction: C
Thread life cycle: automatic management
Frequency of use: frequently used
4, Nsoperation
Introduction: Based on CGD (bottom is gcd), more than gcd more simple and practical functions, using more object-oriented
Language: OC
Thread life cycle: automatic management
Frequency of use: frequently used
iOS Threading summary (continuous update ing)