RaghavBang
Published in

RaghavBang

Concurrency vs Parallelism vs Multithreading

Recently, I was reading about async process and at that moment, I got confused between Concurrency, Parallelism and Multi-threading. When I started to find difference between these three, I didn’t get perfect answer at one place. At a point, I was confused with queries like:

How is concurrency related to parallelism?

How is Multi-threading related to concurrency and parallelism ?

What is difference between task and thread?

I guess many of us get confused about these terminologies.

So let us get started with it. We would analyse and understand what actually they are and their relationship between one another. We will keep our discussion concise 😉.

We must know few terminologies before getting started.

A thread is the smallest unit of execution that lies within the process. A process can have multiple threads running.

A task is simply a set of instructions loaded into the memory. Threads can themselves “split themselves” into two or more simultaneously running tasks. An execution of thread results in a task.

Context Switching means storing the state of a process so that it can be reloaded when required and execution can be resumed from the same point as earlier.

This might seems confusing but reading it twice or thrice will help you to understand the difference between them.

Parallelism

Parallelism occurs only when a computer has more than one CPU or CPU core.

The term parallelism means that an application splits its one task into subtasks which can be processed in parallel, for instance on multiple CPUs at the exact same time.

Note that for parallelism on each CPU one or more thread is needed. In above example, all four subtask are getting executed at same time.

Concurrency

Concurrency means that an application is making progress on more than one task at the same time.

Case 1:

If the computer only has one CPU to make progress on more than one task concurrently the CPU switches between the different tasks during execution with help of context switching.

Case 2:

If computer has more than one CPU, then concurrency can be achieved through parallelism. Threads executed on the same CPU are executed concurrently, whereas threads executed on different CPUs are executed in parallel.

Note that when we use concurrency with parallelism, we may gain or loose performance. Also benefits of concurrency and parallelism may be lost as in Case 2, the task might be divided into subtask or may not be.

Multi Threading

Multithreading means allowing multiple threads to be created within a process, executing independently but concurrently sharing process resources.

Multithreading simply means that a computer system is capable of handling multiple execution flows i.e. threads simultaneously. Multithreading is rather a feature of an OS than CPU.

Concurrency refers managing multiple threads of execution as CPU keeps switching between different task.

Parallelism is more specifically, multiple threads of execution executing simultaneously. As all subtask get executed at same time.

Do Remember that thread get splitted into task.

It is quite confusing to understand the difference between them but I hope by this article it will be much clear.

If you like this post and find it helpful you can give me claps 😍!!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store