Problem Statement
What is the reader-writer problem, and how might an OS handle it? Include considerations for read-heavy vs write-heavy workloads.
Explanation
The reader-writer problem is a classic concurrency scenario where multiple threads/processes can read a shared data resource simultaneously, but writes must be exclusive. The OS or synchronization library must ensure that while writers are active no readers read, and vice versa, or else consistency might break. For read-heavy workloads you might favour many concurrent readers and delay writers (reader-preference), but this risks writer starvation; for write-heavy you might favour writers or use priorities. Solutions include read/write locks, semaphores, or monitors. In interviews, showing awareness of trade-offs (fairness vs performance) is valuable.
