```
package main
import (
"fmt"
"time"
"sync"
)
var wg sync.WaitGroup
var c chan int
func f() {
defer wg.Done()
c = make(chan int, 1)
time.Sleep(2 * time.Second)
c <- 1
}
func main() {
wg.Add(1)
go f()
select {
case m := <-c:
fmt.Println(m)
case <-time.After(10 * time.Second):
fmt.Println("timed out")
}
wg.Wait()
}
```
```
package main
import (
"fmt"
"time"
"sync"
)
var wg sync.WaitGroup
var c chan int
func f() {
defer wg.Done()
c = make(chan int, 1)
time.Sleep(2 * time.Second)
c <- 1
}
func main() {
wg.Add(1)
go f()
select {
case m := <-c: // 这个c的地址和函数f() 中c的地址已经不一样了,现在监听的一直是nil
fmt.Println(m)
case <-time.After(10 * time.Second):
fmt.Println("timed out")
}
wg.Wait()
}
```
#1