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 ~