This is similar to go tutorial select statement, but I didn't get answer from that post. So I asked here. Thanks for answering.
In http://tour.golang.org/concurrency/5, it seems "case c <- x:" is always ready, which means this case will not block select statement.
Based on the sentence "A select blocks until one of its cases can run, then it executes that case. It chooses one at random if multiple are ready.", when "case <-quit:" is also ready, the select statement should randomly choose from "case c <- x:" and "case <-quit:". But the program always go into the "case <-quit:" case.
I also changed the select block to be like below. Then in the first 10 loops, the program randomly print 1-6, but the the program quits once (the 11th output) the quit channel has value 0.
My question is that if the ready cases are randomly selected from, then why the 11th selection is alway the quit case.
select {
case c <- 1:
x, y = y, x+y
case c <- 2:
x, y = y, x+y
case c <- 3:
x, y = y, x+y
case c <- 4:
x, y = y, x+y
case c <- 5:
x, y = y, x+y
case c <- 6:
x, y = y, x+y
case <-quit:
fmt.Println("quit")
return
}