1. Process
1.1> process refers to an application running in the system. (when both QQ and Xcode are enabled, the system starts two processes respectively)
1.2> each process is independent, and each process runs in its dedicated and protected memory space.
2. threads
1.1> A process must have a thread (each process must have at least one thread, that is, the main thread) to execute a task)
1.2> A thread is the basic execution unit of a process. All tasks of a process are executed in the thread.
3. Multithreading
3.1> multiple threads can be enabled in a process, and each thread can execute different tasks in parallel (at the same time ).
Process → workshop, thread → Workshop worker
3.2> multithreading technology can improve program efficiency
4. multithreading Principle
4.1> at the same time, the CPU can only process one thread, and only one thread is working (executed)
4.2> multi-thread concurrent (concurrent) execution is actually a fast CPU scheduling (switching) between multiple threads)
4.3> If the CPU scheduling thread time is fast enough, it creates the illusion of multi-thread concurrent execution.
5. Advantages and Disadvantages of Multithreading
5.1> advantages of multithreading:
(1) appropriately improving program execution efficiency
(2) appropriately improving resource utilization (CPU and memory usage)
5.2> multithreading disadvantages:
(1) enabling a thread requires a certain amount of memory space (by default, the main thread occupies 1 M, and the sub-thread occupies KB). If a large number of threads are enabled, it will occupy a large amount of memory space and reduce program performance.
(2) The more threads, the higher the CPU overhead on the scheduling thread.
(3) More Complex Program Design: for example, inter-thread communication and multi-thread data sharing
6. main thread
6.1> after an iOS program runs, one thread is enabled by default, which is called "main thread" or "UI thread"
6.2> main functions of the main thread
(1) display \ refresh the UI
(2) handling UI events (such as click events, rolling events, and drag and drop events)
6.3> main thread usage notes
(1) do not put the best operations in the main thread.
(2) The operation will be stuck in the main thread, seriously affecting the smoothness of the UI, giving users a "card" Experience
7. multi-thread implementation solution