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!
1 Answer
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.

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!