Ridwan Yusuf
2 min readNov 16, 2022

--

Concurrency and Parallelism demystified Part 1

These two concepts provide different ways to solve multiple tasks (or single task with sub tasks) with the sole aim of decreasing the execution time of a program or system (i.e. Improving Performance)

Concurrency:

Say you (a single person) has three tasks (Cooking the food, Cleaning the house, and washing the clothes) at hand which need to be completed in the minimum amount of time possible.

You put the food items on the lighted stove pot, then quickly move to cleaning the house. After few minutes cleaning the house, you rushed to the washing machine to load some clothes into it. At some point to stop, and then move back to cooking again, and you repeat this process until you are finally done with all the three(3) tasks.

At the of the day, you spend lesser time executing the three tasks by switching context between them than waiting to complete each individual task before starting the next one.

In a single core CPU, the ability to be able to switch between multiple tasks is known as Concurrency.

For instance, the system starts Task A and at some point, pause the execution of Task A, then move to Task B. The order of execution does not matter.

Parallelism on the other hand means executing multiple tasks(or a single task broken into sub tasks) at exactly the same time(i.e. simultaneously).

Parallelism leverages multiple processing units (Multi-core computers) by assigning each one task to each a core; making it to rely on the computer hardware resources.

Going by the same analogy above, you called upon two other friends of yours so that each of the three tasks can be distributed evenly.

Three of you start the assigned task simultaneously. At the of the day the tasks get completed faster than waiting to complete each individual task before starting the next one.

I will conclude with a saying by Rob Pike which sums up the difference between the two concepts: Concurrency is about dealing with lots of things at once. Parallelism is about doing lots of things at once.

Enjoyed this article?

Feel free to explore my video collection on YouTube for more educational content. Don’t forget to subscribe to the channel to stay updated with future releases.

--

--

Ridwan Yusuf

RidwanRay.com -I provide engineers with actionable tips and guides for immediate use