- The CPU of the computer is the core, it handles all the computational tasks, the equivalent of a factory
- Suppose a factory is allowed to operate only one workshop, that is, a single CPU can only run one process, when other processes are in a non-operational state, the workshop is equivalent to the process
- But in a workshop, there can be a lot of workers, many workers work together to run things inside the workshop, this is the multi-line Cheng process running tasks, a process can have multiple threads
- Workshop Some rooms can allow multiple workers to enter, that is, the memory of the process can be shared, each thread can use the shared memory
- Some rooms accommodate more people, while toilets allow only one person to go in, that is, when sharing memory, only one thread is allowed to operate, other threads wait (blocking)
- Prevent others from entering the test with a lock, which is a mutex (Mutual exclusion, abbreviated mutex), preventing multiple threads from reading a memory address at the same time
- But there are also rooms that allow more than one person, that is, some memory areas can only be used for a fixed number of threads, put a few keys in the doorway, enter a person to take a key, this is called the semaphore (Semaphore)
The operating system is designed so that it boils down to three points:
(1) Multi-process mode, allowing multiple tasks to run simultaneously;
(2) in multi-threaded form, allowing individual tasks to be divided into different parts of the operation;
(3) Provide a coordination mechanism to prevent conflicts between processes and threads, and to allow the sharing of resources between processes and threads on the other.
Relationship of processes and threads