Concurrency Vs Parallelism: Simplified

Vishesh Jha
3 min readJul 21, 2021

--

Computers and software programs are useful because they can complete a great deal of heavy lifting very quickly, and they can also complete multiple tasks at the same time. We want our programs to be able to do multiple tasks at the same time. The success of a programming language depends on how easy it is to write and understand multitasking programs. Concurrency and parallelism are two terms that definitely go together when considering multitasking and are often used interchangeably. However, they mean two different things.

Concurrency

Concurrency is about dealing with a lot of things at once. What does it mean?

Well, one of the simplest example that I came across explaining concurrency is the jogging example.

Let’s consider that you are jogging. While jogging you realise that your shoelaces are untied.You stop running and tie your shoelaces and then continue running .

This is a classic example of concurrency. You are capable of handling both running and tying shoelaces which means you are able to deal with lots of things at once.

You must be wondering what about parallelism then?

Parallelism

Parallelism is about doing lots of things at once.

Let’s continue with the previous example to understand it better. Let’s consider that while jogging you are listening to music as well at the same time. Now this act of listening to music while running is parallelism. You are doing multiple things at the same time.

Real world example

We know that web browsers comes with various components. Let us consider that in our case it has only two components , one is to render web page , other to download. Both these components can be executed independently.

So, when this browser runs on a single core processor, the process will context switch between the two components of your browser.It might be downloading a file for some time and then it might switch to render web page. This is concurrency .

The scenario is different when the same browser runs on a multi-core processor. In this case, download component and web page rendering can run simultaneously in different cores. This is parallelism.

It may appear that parallelism always results in faster execution time but that is not the case .

Why?

This is because component running in parallel might have to communicate with each. Say, in our previous example of web browser, if the download completes then it needs to communicate to the user using popup. This communication happens between the component responsible for downloading and the component responsible for rendering the user interface. This communication overhead is low in concurrent systems. In the case when components run in parallel in multiple cores, this communication overhead is high. Hence parallel programs do not always result in faster execution time!

Resources for better understanding

If you take a sneak peak to “Concurrency is not parallelism” by Andrew Gerrand , it gives us a bird eye view of the concept. In the blog he mentions

“Concurrency is the composition of independently executing processes, while parallelism is the simultaneous execution of (possibly related) computations. Concurrency is about dealing with lots of things at once. Parallelism is about doing lots of things at once.”

Do check out the blog https://blog.golang.org/waza-talk . Also, Rob Pike’s talk Heroku’s Waza conference is a must watch.

Here is the link: https://youtu.be/oV9rvDllKEg

Hope this helps. Happy Learning!

--

--