I have a small snippet of code like this
func main() {
var c chan string
go func() {
c <- "let's get started"//write1
//c <- "let's get started"//write2
//c <- "let's get started"//write3
fmt.Println("wrote the stuff....")
}()
//time.Sleep(3 * time.Second) //adding this always shows fatal exception
c = make(chan string)
fmt.Println(<-c)
}
I do not see the output wrote the stuff....
on console if I uncomment //write2
and write3
code snippet lines. I understand that probably I don't see it is because the channel is unbuffered and totally synchronous, and there is only one read happening outside the channel. However, when program exits, the go routine is blocked, why is there no error like deadlocked...
or something in this case that I see?