I'm new to golang
(whith Java
concurrency background). Consider this peace of code :
package main
import "fmt"
func sendenum(num int, c chan int) {
c <- num
}
func main() {
c := make(chan int)
go sendenum(0, c)
x, y := <-c, <-c
fmt.Println(x, y)
}
When I run this code , I get this error
fatal error: all goroutines are asleep - deadlock!
goroutine 1 [chan receive]:
main.main()
/home/tarrsalah/src/go/src/github.com/tarrsalah/stackoverflow/chan_dead_lock.go:12 +0x90
exit status 2
I know, adding another go sendenum(0, c)
statement fix the issue, ... but
When and Where the deadlock happened ?