Unless I specifically know that a variable will be written rarely and read often, I tend to use `Mutex`. I'm too worried that the preferential treatment of write-locks in an `RWMutex` leads to surprising contention-issues if there isn't an overwhelming relationship between their frequencies. I also assume - given that it has the more complicated semantics - that a `Mutex` is generally cheaper than an `RWMutex`, all things being equal.
So I tend to handle it the exact opposite of what you suggest - unless I have a specific reason to use `RWMutex`, I default to `Mutex`. On Sun, Dec 20, 2020 at 9:44 AM 김용빈 <[email protected]> wrote: > we usually both read and write for a value. not only read, nor write. > > with that, I feel RWMutex is always right choice. > > when should I use Mutex instead of RWMutex? > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/f597de36-b296-4f59-b756-adb1248387f5n%40googlegroups.com > <https://groups.google.com/d/msgid/golang-nuts/f597de36-b296-4f59-b756-adb1248387f5n%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAEkBMfEvPFgq-cQ41Bi%3D4OtaNait-k-2iXG3yWTb8Yj%2BjHDM3Q%40mail.gmail.com.
