1、闭包的坑
案例1:
package main import ( "fmt" "sync" "time" ) func main() { wg := sync.WaitGroup{} wg.Add(2) for i := 0; i < 2; i++ { go func() { prefix := fmt.Sprintf("%d", i+1) for c := 'A'; c <= 'A'; c++ { fmt.Printf("%s:%c\n", prefix, c) time.Sleep(time.Millisecond) } wg.Done() }() } fmt.Println("Card") wg.Wait() }
输出如下:
标签:wg,fmt,sync,并发,func,go,main From: https://www.cnblogs.com/wuchangblog/p/17059467.html