How to Solve the Reader-Writer Problem with Strict Reader Priority?
Asked by
CuriousCoder92
I'm currently tackling the Reader-Writer Problem using semaphores and I need some help implementing a version that enforces strict reader priority. This means that if a new reader arrives, they should get to execute even if there are writers waiting. Essentially, no reader should wait if there's already another reader active just because a writer is waiting. I've understood that a writer can only proceed once all current readers have finished. However, if a new reader shows up while the first reader is completing, that new reader should take priority over any waiting writers. Can anyone help me with a semaphore implementation for this? I really need it soon!
Answers
Youโve got the concept down! With strict reader priority, existing readers canโt be interrupted by waiting writers. If a new reader arrives while thereโs a reader active, it gets priority! However, we canโt do the implementation for you, but if you share your code, we can help debug it.
Reply to this answer
Add your answer
Answers are reviewed before publication.
DebuggingDude: Here's the code snippet you provided, but there are some issues that need fixing. Make sure that when a new reader arrives, they acquire the `rw_mutex` correctly only if theyโre the first reader. Let's work through your logic!