package main
import ("fmt"
"sync"
)
var (
count int
rwLock sync.RWMutex
)
func main() {
for i := 0; i < 2; i++ {
go func() {
for i := 1000000; i > 0; i-- {
rwLock.Lock()
count ++
rwLock.Unlock()
}
fmt.Println(count)
}()
}
fmt.Scanf("\n") //等待子线程全部结束
}
mian程等待其他写成退出的小技巧package mainimport ("fmt" "sync")var ( count int rwLock sync.RWMutex)func main() { for i := 0; i < 2; i++ { go func() { for i := 1000000; i > 0; i-- { rwLock.Lock() count ++ rwLock.Unlock() } fmt.Pr