go 实现两个协程交替打印 1-100 的奇偶数
func main() {
var c = make(chan struct{})
go func() {
for i := 1; i <= 100; i++ {
c <- struct{}{}
if i%2 == 0 {
fmt.Println(i)
}
}
}()
go func() {
for i := 1; i <= 100; i++ {
<-c
if i%2 != 0 {
fmt.Println(i)
}
}
}()
select {}
}