The dining hall cooking process helps you understand concurrency and parallelism:
One day the canteen only opened two Windows, so only two aunts are responsible for it. Because there are only two Windows, so you know, both lines are huge.
Under normal circumstances, two aunts are responsible for their Windows, until the end of work —- this is parallel.
But today unfortunately, one of the aunts had to leave temporarily. So there’s only one aunt left to handle the two Windows. Facing these two huge lines, my aunt raised her spoon and said:
“I only have a person, you these two lines of teams, on the rotation of a team of a team”, so aunt finally to each student have played a good meal —- this is concurrent.
To give a more formal definition of concurrency and parallelism:
Parallel: The simultaneous execution of multiple instructions on multiple processors at the same time. Parallel tasks do not grab resources from each other.
Concurrency: Concurrency refers to the idea that only one command can be executed at a time, but that multiple process instructions are concurrency. In the macro, the task has the effect of simultaneous execution, but in the micro, it is not simultaneous execution, only the time is divided into several segments, so that multiple processes quickly alternate execution. Concurrent tasks preempt each other’s resources.
Note: As you can imagine, the goal of concurrent programming is to make full use of every processor core to achieve maximum processing performance.