func main() {
wg := sync.WaitGroup{}
wg.Add(1)
num := 28
a := make(chan int)
b := make(chan int)
go func() {
defer wg.Done()
for i := 1; i < num; {
<-a
fmt.Println(i)
i++
fmt.Println(i)
i++
b <- 1
}
}()
go func() {
defer wg.Done()
for i := 'a'; i < 'z'; {
<-b
fmt.Printf("%c", i)
i++
fmt.Printf("%c", i)
i++
a <- 1
}
<-b
}()
a <- 1
wg.Wait()
close(a)
close(b)
输出 12AB34CD56EF78GH910IJ1112KL1314MN1516OP1718QR1920ST2122UV2324WX2526YZ2728