It's because the goroutine executing the main function blocks until the last channel send completes. But since you don't have another goroutine receiving from the channel the program cannot continue and remains in a blocked state. This is the cause of the deadlock.
On Tue, 29 Jan 2019, at 8:55 AM, 伊藤和也 wrote: > I know the general meaning of a deadlock, but I don't know the meaning of a > deadlock in golang. For example, I send 4 values to a buffered channel whose > maxmum size is 3 and a deadlock occurs. I think this is just "values are out > of bounds" like array. What does a deaklock mean in golang? > func main() { > ch1 := make(chan int, 3)** **** **ch1<- 10** **** **ch1<- 20** **** **ch1<- 30** **** **ch1<- 40** **} > > fatal error: all goroutines are asleep - deadlock! > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.