Second, threading and process
1. Process
Process is a computer program on a data set on a running activity, the system is the basic unit of resource allocation and scheduling, is the basis of the operating system structure, each process has its own independent virtual memory space. Apricot color source Building qq:2152876294 URL diguaym.com
Simply put, a process is an application that is running in the system, each of which is a process, and the processes are independent, each running within its dedicated and protected memory space.
2. Threads
threads, which are the smallest unit threads of program execution flow, are a single sequential control process in a program. is a relatively independent, scheduled execution unit within the process, which is the unit of dispatch of the system to dispatch and dispatch the CPU.
In a nutshell, 1 processes have to be wired to perform tasks.
The execution of a task in a thread is serial, and in order to perform multiple tasks in 1 threads, the tasks can only be executed one at a time, that is, 1 threads can only perform one task during the same period, thus understanding that the thread is the 1 execution path in the process.
A process that contains at least one thread, the main thread, is created to open a new execution path, run the specified code, and run concurrently with the code implementation in the main thread.
3. Multithreading
Multithreading (multithreading) is a technique that implements concurrent execution of multiple threads from software or hardware. Computers with multithreaded capabilities can perform more than one thread at the same time because of hardware support, thereby improving overall processing performance.
Principle:
At the same time, the CPU can only handle 1 threads, and only 1 threads are working (executing)
Multi-threaded concurrency (simultaneous) execution, in fact, the CPU is quickly dispatched between multiple threads (switching)
If the CPU schedules threads fast enough, it creates the illusion of multi-threaded concurrency execution
Note: Multithreading concurrency, not the CPU at the same time to perform multiple tasks simultaneously, but the CPU is dispatched fast enough to create the illusion.
Advantages:
To improve the execution efficiency of the program appropriately
Can appropriately improve resource utilization (CPU, memory utilization)
Disadvantages:
Open threads need to occupy a certain amount of memory (by default, the main thread takes up 1M, the child threads occupy 512KB), if you open a large number of threads, will consume a lot of memory space, reduce the performance of the program
The more threads, the greater the overhead of the CPU on the dispatch thread
Apricot color Source Building and iOS multi-threaded explanation