一、介绍
sync.RWMutex为读写锁,源码位置在src/sync/rwmutex.go
我们使用命令 go doc sync.RWMutex

type RWMutex struct {
    w           Mutex  // held if there are pending writers
    writerSem   uint32 // semaphore for writers to wait for completing readers
    readerSem   uint32 // semaphore for readers to wait for completing writers
    readerCount int32  // number of pending readers
    readerWait  int32  // number of departing readers
}
func (rw *RWMutex) Lock()
func (rw *RWMutex) RLock()
func (rw *RWMutex) RLocker() Locker
func (rw *RWMutex) RUnlock()
func (rw *RWMutex) Unlock()

我们可以知道 rwmutex.go 文件主要有 RWMutex结构体以及Lock()、RLock()、RLocker()、RUnlock()、Unlock() 5个方法组成。

谢谢您的观看,欢迎关注我的公众号。

image.png


海生
104 声望32 粉丝

与黑夜里,追求那一抹萤火。