What Is the Difference Between Concurrency and Parallelism?
Examples Are Appreciated. 7 38 Answers 1 2 Next Concurrency Is When Two or More Tasks Can Start, Run, and Complete in Overlapping Time Periods. It Doesn't...
What is the difference between concurrency and parallelism?
Examples are appreciated.
38 Answers
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.
Quoting Sun's Multithreaded Programming Guide:
Concurrency: A condition that exists when at least two threads are making progress. A more generalized form of parallelism that can include time-slicing as a form of virtual parallelism.
Parallelism: A condition that arises when at least two threads are executing simultaneously.
Why the Confusion Exists
Confusion exists because dictionary meanings of both these words are almost the same:
- Concurrent: existing, happening, or done at the same time(dictionary.com)
- Parallel: very similar and often happening at the same time(merriam webster).
Yet the way they are used in computer science and programming are quite different. Here is my interpretation:
- Concurrency: Interruptability
- Parallelism: Independentability
So what do I mean by above definitions?
I will clarify with a real world analogy. Let’s say you have to get done 2 very important tasks in one day:
- Get a passport
- Get a presentation done
Now, the problem is that task-1 requires you to go to an extremely bureaucratic government office that makes you wait for 4 hours in a line to get your passport. Meanwhile, task-2 is required by your office, and it is a critical task. Both must be finished on a specific day.
Must Read
Case 1: Sequential Execution
Ordinarily, you will drive to passport office for 2 hours, wait in the line for 4 hours, get the task done, drive back two hours, go home, stay awake 5 more hours and get presentation done.