It occurred to me that there is a really simple way to illustrate the difference if you’re struggling with the concept yourself. There is also a great talk by Rob Pike called “Parallelism is not Concurrency” that may help you, too, that goes a lot deeper into the comparison.
Some Kind of Process
Let’s use an example of a computer assembly line. We can define a series of steps that must be followed to properly build our computer. Each stage is as follows:
- Place empty case on conveyor and put the cover beside it..
- Insert and fasten the motherboard to the case.
- Insert the CPU, Memory and a graphics card.
- Insert a disc drive and a hard drive.
- Finally, insert the power supply unit, hook up all the cables and close the case.
Note: A common word, and metaphor, for a process like this is a “pipeline” because the product of each stage flows into the next and only travels in one direction.
Each step is dependant on the one that comes before but each can be worked on independently of the others. Each stage can have a separate person working on them or a single person moving between each step.
Concurrency, to my mind, is taking a process, a task that requires a specific order, that you can divide up into steps that can be worked on independently of the others.
Adding a second line, completely separate of the others, is an example of parallelism. It requires, at minimum, two separate workers for each line.
Concurrency in Parallel
A single worker is like a single core CPU. This worker must manage its time between each task, bouncing between each stage.
This same process can have many workers each one attached to a stage in the process. This is a concurrent solution that has been parallelized.
Concurrency is a design pattern solution and does not have direct hardware constraints. Concurrency solutions can run in serial but often can be easily run in parallel.