直接上代码:
1. 第一种情况, 如果没有select{}, main 主线程不会等待coroutine运行,导致coroutine得不到机会运行。
You are requesting eventual scheduling (using the two go statements)
of two goroutines and then you exit main without giving the scheduler
a chance to do anything.
有了select, 程序正常运行。
- package main
- import (
- "fmt"
- "time"
- )
- func main() {
- go func1()
- go func