多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
> ### 读写锁 ~~~ package main import ( "time" "sync" "fmt" ) var number int //同时操作时只能一个G写或多个G读) var rwm sync.RWMutex func main() { go func() { for i := 0; i < 3; i++ { rwm.Lock() number++ fmt.Println("G1", number) time.Sleep(time.Second) rwm.Unlock() } }() go func() { for i := 0; i < 3; i++ { rwm.RLock() fmt.Println("G2", number) time.Sleep(time.Second) rwm.RUnlock() } }() go func() { for i := 0; i < 3; i++ { rwm.RLock() fmt.Println("G3", number) time.Sleep(time.Second) rwm.RUnlock() } }() time.Sleep(time.Second * 10) } ~~~ > ### 相关阅读 * [锁及锁粒度的详细比喻](https://www.cnblogs.com/nancymake/p/6252536.html)