Concurrency vs. Parallelism

Ankit Sahay
3 min readMay 27, 2022

--

Lines begin to blur when we try to articulate the exact difference between concurrency and parallelism, but make no mistake, they are very different concepts and in this article we will try to understand them.

Concurrency

Lets begin with an example. Suppose you are cooking, for which you need to soak few things, pre heat the oil and cut some vegetables. These three task are independent in nature and we don’t need to finish one before starting the other task. So, you put the materials to soak and then start the gas to heat the oil and while this is happening you begin to cut the vegetables.
Now, take a note that while you are cutting the vegetables, 3 tasks are happening “concurrently”, soaking, heating and cutting. But also note that the 3 tasks have been done by a single worker (you) and you could not have done these tasks all at once but instead did it by switching between them. This switching between the task that the OS does is called concurrent behavior, which means at any given point the OS is only doing one task actively (cutting vegetable, in our case). Different OS have different algorithm of switching between different tasks.

Parallelism

Going back to our cooking example, now consider that you have another friend who is helping you. Now, there are tasks which are happening in “parallel” without you having to switch between them. Multiple tasks gets executed actively all at the same time.

Putting this into terms of applications run by our operating system, let’s imagine it has two applications running. In a system that is only concurrent, we can switch between running these applications, running one application for a short while before letting the other one run. If we do this fast enough, it gives the appearance of two things happening at once. In a system that is parallel, two applications are running simultaneously, and we’re actively running two things concurrently.

Concurrency is about multiple tasks that can happen independently from one another. We can have concurrency on a CPU with only one core, as the operation will employ preemptive multitasking to switch between tasks. Parallelism, however, means that we must be executing two or more tasks at the same time. On a machine with one core, this is not possible. To make this possible, we need a CPU with multiple cores that can run two tasks together.

To conclude in a one liner: In concurrency we switch between running two applications, while in parallelism we actively run two applications simultaneously, which is illustrated in the image below

--

--

Responses (1)