1. A preliminary understanding of multithreading
Multithreading means that the CPU performs high-speed switching between multiple software, giving people a feeling of simultaneous execution.
- Multithreading is the execution of multiple applications at the same time.
- Multithreading requires hardware support.
2. Parallel and concurrency
Parallel: At the same time, multiple instructions are executed simultaneously on multiple CPUs .
Concurrency: At the same time, multiple instructions are executed alternately on a single CPU .
3. Processes and threads
Process: A running application in the operating system.
- Independence: A process is a basic unit that can run independently, as well as an independent unit for system resource allocation and scheduling.
- Dynamic: The essence of the process is the one-time execution of the program. The process is dynamically generated and died dynamically.
- Concurrency: Any process can execute concurrently with other processes.
Thread: It is a single sequential control flow in a process and an execution path. In layman's terms, a thread is what is done in a process.
- Single-threaded: If a process has only one execution path, it is called a single-threaded program.
- Multithreading: If a process has multiple execution paths, it becomes a multithreaded program.