Golang sync. Cond class

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

It is well known that the support of the Go language in multithreading is very complete. A cond class is provided in the Go Language Sync package, which is used for collaboration between Goroutine.

This class is not complex, only three functions, broadcast (), Signal (), Wait (), a member variable, L Lock

One of the functions implemented by broadcast () is to wake up all goroutine waiting on this cond, while signal () selects only one to wake. Wait () Nature is to let Goroutine in

The cond on the waiting. These functions have several points to note:

The 1.Wait () function must ensure that it has obtained its member variable lock L when called, because the first thing to do is unlock. However, it is important to note that when wait () finishes waiting to return, the

It will re-lock the L, which means that when wait ends, the goroutine that calls it still gets lock L.

2. Calling the broadcast () function causes the system to switch to the goroutine that was previously waiting for execution.

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.