Multithreading principle
1. Use multi-threaded purpose: The time-consuming operation in the background to execute, after the completion of execution, notify the main thread to update the UI
2. Principle:
Single Core CPU: At the same time, the CPU can only process one thread, in other words, at the same time only one thread is executing
Multi-threaded simultaneous execution: The CPU is fast switching between multiple threads; CPU Scheduler threads are fast enough to result in multi-threaded simultaneous execution
If there are a lot of threads: the CPU switches between n threads, consumes a lot of CPU resources, the number of times each thread is dispatched is reduced, and the execution of the thread is less efficient.
3. Advantages and disadvantages of multithreading
Advantages: It can improve the execution efficiency of the program; Increase resource utilization (CPU, memory)
Cons: Open threads need to occupy a certain amount of memory (by default, each thread occupies 512kb--ios8.0 and the default stack of the main thread is 512KB)
If you open a large number of threads, will take up a lot of space, reduce the performance of the program, the CPU on the scheduling thread of the greater the cost
Threads are more complex in program logic, such as inter-thread communication and multi-threaded data sharing
4. Multi-threaded implementation scheme
Multi-threaded essay Knowledge Point summary 2