Go Series Tutorial--20. Getting Started with concurrency

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed. Welcome to the 20th chapter of our [Golang Series Tutorial] (HTTPS://STUDYGOLANG.COM/SUBJECT/2). **go is a concurrency language, not a parallel language * *. Before we discuss how Go handles concurrency, we have to understand what concurrency is and how concurrency differs from parallelism. # # What is concurrency? Concurrency refers to the ability to handle multiple tasks at once. An example would be a good way to illustrate this point. We can imagine a man running. If he ran in the morning, the shoelace was suddenly loose. So he stopped, tied his shoelaces, and then went on running. This example is typical of concurrency. This person is able to take care of running and lacing two things, that is, to deal with multiple tasks immediately. # # What is parallelism? What is the difference between parallelism and concurrency? Parallelism refers to processing multiple tasks at the same time. It sounds similar to concurrency, but it's totally different. We also use this example of running to help understand. If the man is jogging, he still listens to music with his ipod. Here, he listens to music while he is running, that is, he handles multiple tasks at the same time. This is called parallelism. # # from a technical perspective concurrency and parallelism through real-world examples, we've learned what concurrency is, and how concurrency differs from parallelism. As a geek, we then look at concurrency and parallelism from a technical standpoint. :) Suppose we were writing a Web browser. This web browser has various components. Two of them are the render area of the Web page and the downloader that downloads the file from the Internet. Let's say we've built the browser code, and the components can be run independently of each other (through threads like Java, or through [go] (#) in the go language that is about to be introduced). When the browser is running on a single-core processor, the processor will switch context between the two components of the browser. It may download files for a period of time and instead render the Web pages requested by the user. This is concurrency. Concurrent processes start at different points in time and run alternately. Here, it is at different points in time to start downloading and rendering, and alternating with each other. If the browser is running on a multi-core processor, the components that download the file and the components that render the HTML may run concurrently on different cores. This is called parallelism. [Image] (https://raw.githubusercontent.com/studygolang/gctt-images/master/golang-series/ Concurrency-parallelism-copy.png) parallelism does not necessarily speed up, because components that run in parallel may need to communicate with each other. In our browser example, when a file is downloadedWhen you are done, you should be alerted to the user, such as a popup window. As a result, communication is generated between the component responsible for downloading and the component responsible for rendering the user interface. On concurrent systems, this communication overhead is minimal. But on multi-core parallel systems, the communication overhead between components is high. Therefore, parallelism does not necessarily speed up the operation! # # Go support for concurrent Go programming language native support concurrency. Go uses [go] (#) (Goroutine) and channels (channel) to handle concurrency. In the next tutorial, we'll cover them in more detail. This concludes the presentation of the concurrency. Please leave your feedback and comments. Have a nice day. * * Previous tutorial-[interface-II] (https://studygolang.com/articles/12325) * * * Next tutorial-[Go] (https://studygolang.com/articles/12342) * *

via:https://golangbot.com/concurrency/

Author: Nick Coghlan Translator: Noluye proofreading: polaris1119

This article by GCTT original compilation, go language Chinese network honor launches

This article was originally translated by GCTT and the Go Language Chinese network. Also want to join the ranks of translators, for open source to do some of their own contribution? Welcome to join Gctt!
Translation work and translations are published only for the purpose of learning and communication, translation work in accordance with the provisions of the CC-BY-NC-SA agreement, if our work has violated your interests, please contact us promptly.
Welcome to the CC-BY-NC-SA agreement, please mark and keep the original/translation link and author/translator information in the text.
The article only represents the author's knowledge and views, if there are different points of view, please line up downstairs to spit groove

3,280 reads ∙1 likes
Related Article

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.