package main
import (
"fmt"
"sync"
)
var wg sync.WaitGroup
var number, letter = make(chan bool), make(chan bool)
func printInt() {
defer wg.Done()
i := 1
for {
_, ok := <-number
if !ok {
close(letter)
return
}
fmt.Printf("%d%d", i, i+1)
i += 2
letter <- true
}
}
func printLetter() {
defer wg.Done()
l := 'A'
for {
_, _ = <-letter
if l > 'Z' {
close(number)
return
}
fmt.Printf("%c%c", l, l+1)
l += 2
number <- true
}
}
func main() {
wg.Add(1)
wg.Add(1)
go printInt()
go printLetter()
number <- true
wg.Wait()
}
标签:交叉,fmt,打印,chan,number,sync,var,bool,Go
From: https://www.cnblogs.com/liy36/p/17201424.html