concurrent

In the operating system, concurrency refers to the fact that only one instruction (process) is being executed at the same time, and multiple instructions (processes) are executed in rapid rotation (all of which are running on the same processor), so it has the effect of simultaneous execution of multiple instructions (processes) at a macro level (illusion). If you have a laptop, it's single-core. One day, when you were developing the program on PyCharm, you also listened to songs through netease Music (and started two processes at the same time). Actually, these two processes were concurrent, not parallel, because there was only one core, and the CPU could only switch between the two processes in a short interval. So you think it's simultaneous, but it's not. If you open a lot of other programs (processes) besides PyCharm and netease Music, such as wechat, QQ, email, Tencent Video, etc., the CPU will switch back and forth between so many processes that you will feel the computer will be stuck.Copy the code

parallel

When the operating system has more than one CPU, when one CPU executes a process, the other CPU can execute another process. The two processes can run concurrently without occupying CPU resources, which is called Parallel. One important point is that the system must have multiple cpus for parallelism to occur. True synchronization occurs when there are multiple cpus.Copy the code

Concurrency and parallelism

You eat rice, vegetables and beef throughout the meal. Eating rice, vegetables, and beef are all done concurrently. To you, the whole process seems to happen simultaneously. But you're switching back and forth between eating different things. It's just the two of us having lunch. In the course of the meal, you had rice, vegetables, beef. I also ate rice, vegetables and beef. The two of us eat in parallel. Two people can eat beef together at the same time, or one can eat beef and one can eat vegetables. They are mutually exclusive. So, concurrency is when *** multiple programs are running at the same time at a macro level. Parallelism means that multiple tasks are actually running at the same time *** *.Copy the code

The difference between concurrency and parallelism

Concurrency is when multiple things happen ** at the same time ** at the same time. Parallelism refers to multiple things happening at ** the same time. Parallel tasks can't compete with each other (you can't eat rice while you're eating beef, in this case, the resource is the mouth). True parallelism only occurs in the case of multiple cpus. Otherwise, everything that seems to happen at the same time is actually executed concurrently.Copy the code