placeholder

When to use Go's RWMutex

The Go programming language has two flavours of mutex that can be used to serialise access to shared state. They are sync.Mutex and sync.RWMutex. This blog post explains the differences between them and quantitatively analyses why RWMutex may not give performance benefits over Mutex even under read-...

Click to view the original at petsta.net

Hasnain says:

“The graph confirms that mutex contention is highest (and therefore RWMutex is most useful!) when the arrival rate is high or the critical section has a long duration.

The graph shows something else interesting. The transition from “no contention” to “high contention” follows a straight line. If some values at the transition are taken and their product calculated, it’s clear that the product is always a constant.”

Posted on 2024-03-04T06:24:10+0000