golang中sync.Mutex和sync.RWMutex
sync.Mutex互斥锁:所有goroutine都会等待释放一个goroutine的Mutex锁。Lock()、Unlock()sync.RWMutex读写互斥锁:RLock()读锁:阻止写,不阻止读。 RUnlock()Lock()写锁:和Mutex一样,读写都会被阻止。type x struct {a intaLock sync.RWMutex //给结构体单个a数据加读写互斥锁b int}...
原创
2022-03-28 11:25:13 ·
357 阅读 ·
0 评论