First analyze the advantages of the thread: 1, improve the concurrency of the program (thread-level parallelism, rather than instruction-level parallelism);
2. All threads in a process share all resources;
3, the cost of switching threads;
4. Interactive program can improve the response time through multi-threading method.
How to implement Multithreading:
1, the program adopts multi-threaded design scheme;
2, multi-core processor for a single single-threaded program provides a good platform for parallel optimization, is to absorb the implementation of better programs to run the effect.
When a multithreaded design program runs on an SMP platform, multithreading in the process is distributed across multiple cores of the CPU in parallel execution. If the execution process between threads is independent, then the degree of parallelism of the process at this time is the largest, if there is a competition between the resources or need synchronization and communication, its process of parallelism <1. If the structure of multiple threads is a sequential structure and the number of critical resources is 1 o'clock, the multithreaded design is degraded to single-threaded design mode, and its program efficiency is greatly compromised.