Fair-Mutex - an RWMutex implementation which gives equal priority to read and write locks
reddit.com·12h·
Discuss: r/golang
Flag this post

I encountered a scenario recently where I had potential waits in a service that had heavy use of an RWMutex. caters for a relatively low number of write locks when under moderately heavy or persistent read lock use.I felt that this could become a bottleneck, and set out to attempt an implementation of an RWMutex that gave equal priority to write locks as read locks.This has resulted in Fair-Mutex. This is a heavier implementation than or , and it is slower, until there is a high demand for read and write locks when it can begin to outperform .This package includes an OpenTelemetry histogram for recording lock wait times for Lock() and RLock().Again, I want to stress that there is perhaps a fairly narrow use-case for Fair-Mutex, but I believe a valid one all the same.

Similar Posts

Loading similar posts...