The difference between concurrency and parallel

When reading the chapter on parallelism in " real world haskell " recently , I saw that the author first defined and explained the difference between Concurrency and Parallelism. I used to know a little about this problem. If someone has a problem with this problem, I’m afraid I can only scratch my head and make it clear. In this book, the author’s explanation is (simple translation):

A concurrent program refers to the simultaneous execution of various tasks that are not normally related. Take a game server as an example: it usually consists of various components, and each component interacts with the outside world in complex information. One component may have to process multiple user chats; others may have to process user input and feed back the latest status to the user; others may be used for physical calculations. These are all concurrent processing.

Concurrent programs do not require multi-core processors.

In contrast, parallel programs are used to solve a single task. Take a financial component that tries to estimate the price fluctuations of a certain stock in the next minute as an example. If you want to know as fast as possible whether the stocks in the S&P 500 should be sold or bought, you can’t calculate them one by one, but Calculate all these stocks at the same time. This is parallel.

In fact, it’s not very easy to understand. I figured it out for myself. This is probably the truth: concurrency is one mind and two purposes (multiple purposes). For example, you listen to the teacher's lecture while looking down at the novel by Han Han under the desk. You are doing these two things at the same time, and the two things do not necessarily need to be related. Parallelism means the same thing is done in several ways. For example, other people can only read a novel line by line, while you can read ten lines at a glance. This is parallelism. :).

Regarding the difference between concurrency and parallelism, Go language has a very good textbook called " Concurrency is not parallelism ". It uses Go language as an example. It explains the connection and difference between concurrency and parallelism with pictures and texts .

 

Concurrency is not parallel

 

In this article, we use Gopher to burn books as an example, and compare the combined application of concurrent and parallel technologies by designing different processes for concurrently loading, transporting and burning books. The original text is in English, and here is the Chinese version translated by the foreign magazine IT review network. Concurrency is not parallel , for everyone to enjoy. (Hint: This textbook uses HTML5 technology to make a slide show, so you need to use a modern browser that supports HTML5 to view it.)

Concurrency is not parallel

 

Concurrency concurrency is one mind and two purposes. Concurrency executes multiple tasks serially in units of time slices. It appears to be synchronized but not actually synchronized, so concurrency does not require multiple cores. Parallel is a multi-tasking, multiple modules are used to solve a problem at the same time, so multiple cores are required.

Guess you like

Origin blog.csdn.net/michellechouu/article/details/113101745