Goroutine does not execute if time.Sleep included
问题 The following code runs perfectly fine: package main import ( "fmt" ) func my_func(c chan int){ fmt.Println(<-c) } func main(){ c := make(chan int) go my_func(c) c<-3 } playgound_1 However if I change c<-3 to time.Sleep(time.Second) c<-3 playground_2 My code does not execute. My gut feeling is that somehow main returns before the my_func finishes executing, but it seems like adding a pause should not have any effect. I am totally lost on this simple example, what's going on here? 回答1: When