在src/sync/rwmutex.go文件中,我们可以看到“Lock”的定义如下:func(rw*RWMutex)Lock(){ifrace.Enabled{_=rw.w.staterace.Disable()}//First,resolvecompetitionwithotherwriters.rw.w.Lock()//Announcetoreadersthereisapendingwriter.r:=atomic.AddInt32(&rw.readerCount,-rwmutexMaxReaders)+rwmutexMaxReaders//Waitforactivereaders
在src/sync/rwmutex.go文件中,我们可以看到“Lock”的定义如下:func(rw*RWMutex)Lock(){ifrace.Enabled{_=rw.w.staterace.Disable()}//First,resolvecompetitionwithotherwriters.rw.w.Lock()//Announcetoreadersthereisapendingwriter.r:=atomic.AddInt32(&rw.readerCount,-rwmutexMaxReaders)+rwmutexMaxReaders//Waitforactivereaders