关于go:go源码阅读syncRWMutex读写锁

39次阅读

共计 536 个字符,预计需要花费 2 分钟才能阅读完成。

一、介绍
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 个办法组成。

正文完
 0