Concurrency vs. Parallelism
Understand the distinction between concurrency and parallelism and how they apply to Go programming. Learn to design and structure tasks efficiently by breaking down problems into independent subtasks, coordinating and synchronizing them properly. This lesson helps clarify common misconceptions and illustrates these concepts with practical examples to prepare you for advanced concurrency patterns in Go.
A lot of people confuse concurrency with parallelism because they both somewhat imply executing code simultaneously but they are two completely different concepts. This lesson will help you clear up some misconceptions caused by developers using these concepts interchangeably.
"Concurrency is about dealing with lots of things at once.
Parallelism is about doing lots of things at once"
In the previous lesson, we learned about concurrency so let’s discover parallelism now.
What is parallelism?
Parallelism is when we break up a task into subtasks and execute them simultaneously. Each of the subtasks is independent and may or may not be related. In short, we carry out many computations at the same time in parallelism.
The multicore processor in your computer is an example of parallelism where parallel tasks are run on multiple cores to solve problems. In this way, parallel computing helps us solve large problems efficiently by using more than one CPU to execute multiple computations at the same time, which saves time in the case of large datasets.
However, parallel programming is hard to achieve as we need to ensure the independence of tasks when it comes to dividing the problem and sharing the data. This is where concurrency comes into play!
Concurrency and Parallelism are not the same but are closely related to each other.
"Concurrency is about structure. ...