Easy to understand to understand the difference between concurrency and parallelism

Foreword

Concurrency and parallelism of difference, I believe that many inexperienced programmers will be asked this question now, very easy to confuse the two concepts. Today, we'll talk about the difference between the popular concurrency and parallelism.

concept

Before popular explanation, look at the concept of concurrent and parallel bars.

Concurrency: Concurrency (Concurrent), the operating system refers to a time period has started several programs are in the running to finished running between, and these programs are running on the same processor.

Parallel: Parallel (Parallel), when the system has more than one CPU time, when a CPU executes a process, another CPU can execute another process, the two processes are not mutually seize CPU resources, it can be performed simultaneously, in this way we call the parallel (parallel).

parallel

When we play on the computer, the computer can "simultaneously" running music software and IDEA, we can knock on the code side, while listening to music, while the computer is doing more than one thing. In the single-core computer cpu, we seem to be "simultaneous" do these things, but this is not true parallel in the sense that the bottom is due to the illusion cpu fast switching tasks, give us a run of it. However, when the computer is a multi-core cpu time, when a CPU executes a process, another CPU can execute another process, the two processes are not mutually seize CPU resources, it can be performed simultaneously, this time is the real "simultaneously" in we call it parallel. Like, a cafe, several computers it can meet the needs of multiple clients access to the Internet at the same time, this is the parallel, at the same time, and do not compete.

Complicated by

Concurrent, referring to the multiple things that happened in the same period of period of time. Similarly, we can take the cafe here as example. For example, an Internet user volume six in the evening until 10pm daily is particularly large, this time can be called concurrent large. If the cafe has a 100 machine, but six in the evening until 10:00 pm there hundred and fifty to the Internet, this time there are fifty people can not normally access, or the fifty people in this wait, or to leave the cafe . Internet cafes to deal with this request hundred and fifty of the Internet, not to be taken at the same time, but treatment over a period of time. In fact, this is concurrency.

The difference between concurrent and parallel

In general, concurrent, refers to a plurality of things occur simultaneously within the same period; parallel, refers to a plurality of things occur simultaneously at the same point in time. Both are handling multiple things, whether the difference is that "at the same time." It may also be well understood by the following FIG.

Reproduced in: https: //juejin.im/post/5d07a0d6f265da1bb13f3297

Guess you like

Origin blog.csdn.net/weixin_34378922/article/details/93181304