I am implementing a web-app that holds some data in memory. Some requests read this data for processing and some requests update this data.
In this scenario, multiple readers can concurrently operate on the data, but a writer needs exclusive access to the data in memory. I want to implement a reader-writer lock to solve this problem. I also want the fairness property that waiters on the lock are processed in FIFO order to avoid read and write starvation.
The Haskell standard libraries do not appear to provide such functionality. I found concurrency-extra
gives this functionality, but the library seems to be unmaintained (and was removed from stackage after LTS 3.22) - and its fairness properties are not clear to me.
I find it a bit surprising that there is no reader-writer lock library in standard haskell libraries and in stackage - isn't the reader-writer pattern common in many software? Or is there a completely different (perhaps lock-free) approach that is preferred in Haskell?
EDIT: More precisely on the fairness property, when a writer is blocked waiting to acquire the lock, subsequent read-lock requests should be allowed only after the writer acquires and releases the write-lock - similar to MVar
s fairness property - MVar
s have a FIFO property