Concurrency vs Parallelism

Summary

Concurrency describes the ability to manage multiple tasks that appear to run simultaneously, often through time-slicing, where tasks overlap in execution but may not execute at the exact same instant. This approach prioritizes application responsiveness and involves tasks maintaining state about each other. Conversely, parallelism signifies the true simultaneous execution of multiple tasks at the exact same instant, requiring distinct processing units. Its primary goal is to enhance processor utilization by distributing workloads across available cores, operating in a generally stateless manner. Grasping this fundamental difference is essential for architects designing performant and responsive software.

Concurrency and parallelism are two related concepts which deal with executing tasks "simultaneously". From 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.

These two definitions are too formal to be understood easily. On the Internet, there is one image which demonstrates the difference between these two in an easy way:

Concurrent and Parallel Programming

Much easier to understand,right? For concurrency, tasks can start, run and complete in overlapping the time periods, but they may not run at the same instant, when one task in a queue is running, another task in the other queue will wait. While for parallelism, two tasks can run at the same instant. Concurrency has states which means they know status of other tasks execution, while parallelism is stateless.

With concurrency, we want to improve the responsiveness of the application, with parallelism, we want to improve the utilization efficiency of processors, as the computing speed of a single CPU is driving to its limit, so we try to integrate more processors on a single CPU to distribute tasks among different processors.

To clear up this conflation, Rob Pike gave a talk at Heroku's Waza conference entitled Concurrency is not parallelism, below is the video recording. You can get more information from this video.

CONCURRENCY THREAD PARALLELISM

  RELATED

  COMMENTS

0

No comment for this article.