💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
> ### 读写锁 ```go 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)