Concurrency vs Parallelism
This is going to be a brief explanation with resources at the end as usual.
I found more than one explanation , will point out to those that I found intuitive and put links to the detailed sources as well.
First Example:
Consider you have to do some presentation and need to finish some official papers from a bureaucratic government office as well, there are more than one Possibility :
1- Sequential Execution:
you will first finish the task of getting the papers from the government office then do the presentation task.
2-Concurrent Execution:
this is when you take your work laptop with you to make benefit of the commute time and the waiting time for different boring bureaucratic procedures while doing the task of getting the papers from the government office.
In this case the two tasks are still finished by the same person -you -whereas you interrupted the task of the government office while waiting for your number or for any other procedure and started working on the presentation task, then when your turn has come to finalize the papers of the government office you interrupted the presentation task and switch back to the task of getting the papers from the government office. This allows for saving some time so that instead of needing to work an X number of hours for doing the presentation in the sequential execution instance , you might need around 0.2 X of hours to finalize the presentation as you have taken advantage of the waiting time and so on.
In this case the two tasks are still finished by the same person -you -whereas you interrupted the task of the government office while waiting for your number or for any other procedure and started working on the presentation task, then when your turn has come to finalize the papers of the government office you interrupted the presentation task and switch back to the task of getting the papers from the government office. This allows for saving some time so that instead of needing to work an X number of hours for doing the presentation in the sequential execution instance , you might need around 0.2 X of hours to finalize the presentation as you have taken advantage of the waiting time and so on.
3- Parallel Execution:
This is when you have a friend /colleague / assistant that would start the presentation task while you are at the government office finalizing the official papers task. This would save you a lot of time as when you return back from this task , you would need to work for 0.3 X of hours to finalize the presentation task.
In this case the two tasks were performed at the same time by two different executioners.
In this case the two tasks were performed at the same time by two different executioners.
A Definition:
Concurrency is when two or more tasks can start, run, and complete in overlapping time periods. It doesn't necessarily mean they'll ever both be running at the same instant. For example, multitasking on a single-core machine.Parallelism is when tasks literally run at the same time, e.g., on a multicore processor.
Second Example:
I accidentally stumbled upon an explanation by the brilliant Dan Abramov:
in which he made a phone call analogy:
1-Serial/No Concurrency:
I can have only one phone conversation at a time, so that when I am in a phone call with Mahmoud, then Ahmed called me , then I have to finish the call with Mahmoud before I can talk to Ahmed.
2-Concurrent:
Concurrency means that I can have more than one conversation at a time , where I can put Mahmoud on hold and then talk to Ahmed for a bit and then switch back to Mahmoud.
So that concurrency does not mean I can talk to two people at once but at any given moment I can be in more than one call and I chose who to talk to.
short Example : Concurrency is two lines of customers ordering from a single cashier (lines take turns ordering); Parallelism is two lines of customers ordering from two cashiers (each line gets its own cashier).
Resources:
Amazing StackOverflow Answer
Another Amazing Answer from the same Question as above
a very intuitive metaphor using feeding cats
Comments
Post a Comment