No-smell concurrency of the course looked down, and then gave him dizzy, book that, I was platinum poo Ah, temper is very excrement, you do not explain clearly, I go to figure out.
No, the buffer channel does not block, the non-cache channel will block, really?
No, I gave you an example.
Func Main () {C:=make (chan bool,1) Go Fun () {fmt.println ("go!") <-C} () C<-true}
The above code as long as the 1 is removed will output go! do not remove the output go! He says this proves that the buffer channel is not blocked and the non-cached channel is blocked. Well, then it won't superstitious, I'll take a piece of code
Testgo Project Main.gopackage mainimport ("FMT" "Time") Func main () {C:=make (chan bool,1) go func () { Fmt. Println ("go!") <-c FMT. PRINTLN ("123!") } () time. Sleep (1*time. Second) fmt. Println ("111") c<-true time. Sleep (1*time. Second) fmt. Println ("222") time. Sleep (2*time. Second)}
Let's guess, the output is BAA?
Go!
111
123!
222
Success: Process exit code 0.
Process Goroutines in the main process to establish a good pipeline C and the main process at the same time running, main first sleep for 1 seconds, first output goroutines go!, and then take the object from C, note yo, is a buffer pipe yo, according to no smell of the saying should not be blocked yo, Should direct output 123 yo, the result pinch? The toilet is blocked!!! Blocked!!! There is no object in the pipeline, can not be taken out, has been waiting for other processes to plug the object in the pipeline, so long as there is a pipeline, it will be blocked. In my example, the first output is 111, and so the main process to plug the object into the pipeline, the Goroutines process will not block, output 123.
The conclusion is that the cache channel is not blocked
Finally give everyone a long-term work since the advice, do not blindly believe in authority, do not know to try, the teacher said is not necessarily right, there is oneself if you really want to upload video tutorial, please first audit, or fraught AH
51CTO's no-sniff go basic tutorial concurrency-related concepts have errors