I want to implement the famous reader writer model using actor model. We can have multiple reader reading but only one writer can write. Also when a writer writes no reader can read and vice versa.
To solve this problem i thought of using a superviser actor which maintains a set for reader actors and a queue for writer actors. Now a writer can be dequeued and start writing when the set for readers are empty. Also when the writer completes all reader actors from the set can start reading.
Can we have a better problem of solving this famous problem using actor model?
Also is this model better than the original reader writer problem soved using read or write locks?
You may want to look into "software transactional memory" with ScalaSTM libs.
You would create a shared Ref with atomic access. When multiple threads enter an atomic block, both proceed. The first thread to write to the Ref wins, and the loser restarts the atomic block (and thus re-reads) from the beginning. Thus, both threads will always work with up-to-date data.
https://nbronson.github.io/scala-stm/
STM is an alternative to Locks and Mutexes, but has better concurrency as it uses optimistic non-blocking writes as opposed to blocking on both writes and reads. It is also easier to write and maintain STM code than to do so with locks.