This is a creation in Article, where the information may have evolved or changed.
People can only lose if they give up fighting, so long as they insist on fighting, they would not lose.
People, only in the time to give up the fight to lose, as long as the fight, you have not lost.
Golang is a concurrency language rather than a parallel language.
So what is the relationship between parallelism and concurrency?
What is concurrency, parallelism?
Concurrency is the ability to do a lot of things at once.
1. Explanation One: parallelism means that two or more events occur at the same time, while concurrency means that two or more events occur at the same interval.
For example: Every morning 10 minutes I wash my face, brush my teeth, eat breakfast and so many things, this is concurrency. While I was brushing my teeth while I was boiling water and cooking, it was parallel.
The key to concurrency is that you have the ability to handle multiple tasks, not necessarily at the same time. The key to parallelism is that you have the ability to handle multiple tasks at the same time.
2. Explanation Two: Parallelism is multiple events on different entities, and concurrency is multiple events on the same entity.
3. Explanation Three: "simultaneous" processing of multiple tasks on a single processor, processing multiple tasks simultaneously on multiple processors. such as Hadoop distributed clusters
So the goal of concurrent programming is to take full advantage of each core of the processor to achieve the highest processing performance.
Use the technical dimension to illustrate:
If a Web page has video playback and file download two actions, when the browser is running under a single core processor, the CPU core will switch back and forth between these two events, (simultaneously) play the video and download, this is called concurrency. Concurrent processes start at different points in time and have overlapping execution cycles.
The perception of the human eye is simultaneous.
If your CPU is a multi-core processor, then the download and playback will be performed simultaneously at different CPU cores, which is parallel.
Parallelism does not necessarily make execution time faster. This is because components that run in parallel may have to communicate with each other. For example, in our browser, when a file download is complete, it should be passed to the user, such as using a pop-up window. This communication occurs between the component responsible for the download and the component responsible for rendering the user interface. This communication overhead is very low in the concurrency system. This communication overhead is high when components run in parallel across multiple cores. So parallel programs do not necessarily make execution times faster!
Go support concurrency
Use Goroutine and channel in Golang to handle concurrent execution.
concurrency belongs to parallelism.
More about concurrency, parallel introduction can Google Baidu in-depth understanding.