Home
Tags Projects About License

Concurrency and parallelism are two different things

Concurrency and parallelism are two different things

It may seem that there is no difference between concurrency and parallelism, but this is because you have not understood the essence of the question. Let's try to understand how they differ.

Concurrency

Concurrency is the execution of more than one task is being processed in overlapping time periods. An important detail is that tasks are not necessarily performed at the same time(but it's possible). That is based on the notion of Interruptability — tasks can be divided into smaller and alternating subtasks. In this case, they can be executed simultaneously, but this is not necessary.

Subtasks are not connected with each other. Therefore, it does not matter which of them will end earlier, and which later. Thus, concurrency can be realized in many ways — using green threads or processes or asynchronous operations that work on one CPU or something else.

Let's draw an analogy: the secretary answers phone calls and sometimes checks for appointments. He needs to stop answering the phone to go to the desk and check the appointments, and then start answering and repeating the process before the end of the workday.

As you have noticed, concurrency is more connected with logistics. If it were not, then the secretary would wait until the time of the appointment and do the necessary things and then go to the ringing phone.

Parallelism

Parallelism is literally the simultaneous execution of tasks. The very name implies that they are executed in parallel. Parallelism is one of the ways to implement concurrent execution highlighting abstraction of a thread or process. Also for parallelism to be true, there must be at least two computational resources.

Back to the office: Now we have two secretaries. One keeps an eye on the phone, and the other makes appointments. The work is divided because now there are two secretaries in the office and the work is done in parallel.

Parallelism is a subclass of concurrency — before performing several concurrent tasks, you must first organize them correctly.

I also advise you to go read Andrew Gerrand post and watch Rob Pike's talk.


Check out my book on asynchronous concepts:




Buy me a coffee
Next post

More? Well, there you go:

Concurrency vs Parallelism

Asynchronous programming. Await the Future

Asynchronous programming. Python3.5+