The Go language experiment on Chan comprehension

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Programming this thing if you don't write it yourself, you probably never know what's going on.

Before learning go to write some of the gadgets have not been used to Chan this thing (I am PHP), search some articles, found that the great God is written very wonderful, very advanced, but I this small white is not understand, just understand is probably a similar threading mechanism.

Still do not use, had to self-practice under:

I have to say the code sucks, but it's enough for me, mostly understanding! Execution Result:

If you do not use thread goroutine directly as a procedure function, the output order should be STR1...STR5.

Using Goroutine to call thread, it may take a little time for the thread to start, because the main thread is not going to take care of it after Goroutine starts the thread, so the STR3 is output first.

The str1 is then output in thread.

Then because the main thread to take out ch, it waited for 3 seconds, output str2.

And then the STR4.

Wait 3 seconds, output STR5.


After this is still some mengmengdongdong, do not understand what the bright eye of this place, it seems that the actual project can be used to draw conclusions.


============================================

Just started to learn to write some blog, write a bad place please forgive me, feel that learned to pay attention to the next bar ~

My QQ group (PHP)336533596, Welcome to join. Communicate with each other, chat and brag ~



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.