Golang concurrency control

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed. There are two ways of controlling concurrency in Golang: sync. Waitgroup and Channel here are the comparisons between the two methods sync. Waitgroup, the best advantage of this approach is that wait () can block all tasks in the queue before it is unblocked, but its disadvantage is that the number of concurrent threads cannot be specified. Channel Advantages: the ability to use a channel with a buffer to specify the concurrent Goroutine, more flexible. However, its disadvantage is that it is easy to create deadlocks if used improperly, and he also needs to decide whether or not the concurrent goroutine is executed.

However, the channel is more flexible, more convenient to use, and through the time-out processing mechanism can be very good to avoid the channel caused by the program deadlock, so the use of channel to achieve program concurrency, more convenient and easier to use.

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.