Todo:go language goroutine and channel use

Source: Internet
Author: User

Todo:go language goroutine and channel use

Goroutine is a lightweight threading implementation in the Go language, managed by the Go Language runtime (runtime). When using the word "go" in front of the function as a keyword, it is also different from the normal function. You can create a new goroutine for concurrent execution by adding the Go keyword in front of the function.

Go Hello ()

The channel is a way of communication between the goroutine provided by the go language, and we can use the channel to deliver messages in two or more goroutine homes. The key word used by the channel is "Chan", which declares a channel with the type int:

var ch Chan int

Below is a small example of an event that is triggered when the listener process is closed.

Monitor the signal, use

Signal. Notify (c, OS. Interrupt)

The first parameter represents the channel that receives the signal

The second and subsequent parameters indicate the setting of the signal to be monitored, if not set to indicate that all signals are monitored.

Complete examples are as follows, in this case the service version of the Ubuntu14.04 test passed.

The effect of CTRL + C

Effects of the Kill process

Simple example, hope to help you.

Wxgzh:ludong86

Todo:go language goroutine and channel 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.