Question on channels and blocking?

Trying to figure out how go works . and what comes
Why in this case the program is blocked.

func main() {
 intCh := make(chan int) 
 intCh <- 10 // function main is locked

But if the channel has a buffer then it works until the end
func main() {
 intCh := make(chan int,100) 
 intCh <- 10 // function main blokiruet

But I do logic not caught. After the channel should be blocked because someone has to get data from groten (in this case, the main main). As we all launched into the main channel is blocked . But why is it not blocked in the second case. That is, the code comes grottini with a buffer puts data and all, as it with the buffer once it is not blocked. Supposedly this logic and all ?
April 7th 20 at 15:19
2 answers
April 7th 20 at 15:21
A channel in Go is a queue declared capacity(implemented by a circular buffer). If the queue does not get it clogged and blocks.
April 7th 20 at 15:23
Learn how channels work in go.

In the first case, the goroutine will be blocked, because nobody reads from the non-buffered channel.
In the second case, a buffered channel, the goroutine will be blocked therefore only when (in your case) you try to write the 101-th element(read: the channel is filled).
ie goroutine is blocked if the channel is completely filled up. I found kakoeto explanation habré but it's horrible But if I Russian then not until the end understand that the English version tembolee not quite get . )) Anyway thanks)) - Clotilde_Bogan56 commented on April 7th 20 at 15:26
Go go tour. I honestly don't remember, but there is supposed to be. - Jonathon.Wintheiser commented on April 7th 20 at 15:29
Everywhere I read but this time explained like:
now lock the channels without a buffer as the channel filled and no one reads
But there is a buffer they have channels so nothing is blocked. but if the end zapolnit it is blocked but then thought about the mechanics a little upasena was. Well, I didn't catch. - Clotilde_Bogan56 commented on April 7th 20 at 15:32
@dean, non-buffered channel is blocked and waits until it reads. The channel buffer is locked only when it is completely filled. It seems simple) - kellie78 commented on April 7th 20 at 15:35

Find more questions by tags Go