A picture to quickly understand parallelism and concurrency in Golang

Source: Internet
Author: User
This is a created article in which the information may have evolved or changed.


Plain English

The picture above is a reference to the situation of the queuing station, did not find the right picture, had to draw a line chart.

Where A, B is two different wicket windows, two teams of people can be at the same time ticket, which is parallel. One of the ticket gates can be understood as a CPU core, and a team is equivalent to a squad of all the ticket preparation teams. Again, it is more than one ticket window can allow the various ticket-gate teams at the same time.

For A1, and A2, they are after the check-in, choosing around two routes caused. Only through the ticket, in order to go inside, and when the person in front of you to choose the left, the right side may be empty a distance, you for the convenience of walking, not crowded, choose the right to walk, equivalent to you in front of the people to give you out of the right side of the road, gave you access to the right. They are all running at the same ticket gate, adjusting the speed of the team through the left and right roads. This is equivalent to concurrency.


Official words:

concurrency (concurrency) and parallel (parallelism) are different. On a single CPU core, a thread passes the time slice or yields control to achieve a task switch, achieving "simultaneous" running of multiple tasks, which is called concurrency. But in fact, only one task is executed at any moment, and other tasks are queued by some sort of algorithm. Multi-core CPUs allow "multiple threads" in the same process to run at the same time in real sense, without queuing between them (still queued because the number of threads may exceed the number of CPU cores, as well as other processes, etc.). This is an ideal condition), which is parallel. In addition to multicore, parallel computing may also be a deployment run on more than one machine.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.