There are two types of mutex in Go: Mutex
and RWMutex
Mutex
offersfunc Lock()
andfunc Unlock()
.RWMutex
offers those functions plusfunc RLock()
andfunc RUnlock()
.
From what I understand, we should only use RWMutex
when there are many read operations and few write operations, to allow for concurrent reads. It also is more time-consuming to write-lock.
But what if I only use RWMutex
and alternate using func Lock() / func Unlock()
when I want to allow concurrent reads and func RLock
/ func RUnlock
when I want to do the same as a normal Mutex
. Is using RLock
/ RUnlock
the same time as a normal mutex equivalent functions?
TLDR: Why use Mutex
when RWMutex
offers the same functionality with more options?