🎓 BookMCQ
← Back to 5. Process Synchronization

📝 The Readers Writers Problem in Process Synchronization (55 MCQs)

📖 From Operating System • 5. Process Synchronization • 55 questions available

What is The Readers Writers Problem in Process Synchronization?

Definition:
The readers-writers problem manages concurrent access to a shared database where multiple readers can read simultaneously but writers require exclusive access, optimizing throughput based on workload.

Example:
A reader increments readcountreadcount under mutexmutex; if readcount==1readcount==1, it acquires wrtwrt, allowing concurrent reads RnR_n while blocking writers WW.

Reason:
It addresses asymmetric access patterns where read-heavy workloads benefit from concurrency, requiring variants (reader-first, writer-first, fair) to balance fairness and performance.

7
Easy
20
Medium
28
Hard

📝 All The Readers Writers Problem in Process Synchronization MCQs

Q1. The readers-writers problem is a classic synchronization problem that addresses the concurrent access of:

A.A single shared file by multiple processes
B.A database by readers and writers ✅
C.A bounded buffer by producers and consumers
D.A resource by multiple threads
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: The problem specifically deals with a shared database accessed by two types of processes: readers who only view the data and writers who update it. The core challenge is managing their concurrent access to maintain data integrity.

Q2. In the readers-writers problem, which type of process only reads the shared data without modifying it?

A.Reader ✅
B.Writer
C.Both reader and writer
D.Neither
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: Readers are defined as processes that only read the shared database. They do not perform any updates or modifications, distinguishing them from writers who perform both read and write operations.

Q3. What synchronization requirement is enforced for writers in the readers-writers problem?

A.Writers must share access with readers
B.Writers must have exclusive access to the database while writing ✅
C.Writers can access the database only when no readers are waiting
D.Writers must wait for other writers to finish
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: Writers require exclusive access to the shared database. This ensures that no other process (reader or writer) accesses the data while a writer is updating it, preventing data corruption and inconsistency.

Q4. In the first readers-writers problem, what is the priority given to readers?

A.No reader is kept waiting unless a writer has already obtained permission ✅
B.Readers must wait for all writers to finish
C.Writers always have priority over readers
D.Readers and writers have equal priority
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: The first readers-writers problem, also known as the reader-priority problem, specifies that no reader should wait for other readers to finish simply because a writer is waiting. A reader only waits if a writer is already actively using the shared object.

Q5. In the second readers-writers problem, what priority is given to writers?

A.Once a writer is ready, it performs its write as soon as possible ✅
B.Writers must wait for all readers to finish
C.Readers always have priority over writers
D.No writer is kept waiting unless a reader is reading
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: The second readers-writers problem, also known as the writer-priority problem, ensures that once a writer is ready, it gets to write as soon as possible. This means no new readers may start reading if a writer is waiting.

Q6. Which synchronization primitive is commonly used to solve the readers-writers problem?

A.Mutexes
B.Semaphores ✅
C.Monitors
D.Condition variables
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: Semaphores are a standard synchronization primitive used to solve the readers-writers problem. The solution uses semaphores like `rw_mutex` and `mutex` to control access and manage the critical sections for readers and writers.

Q7. What is the initial value of the `rw_mutex` semaphore in the solution to the first readers-writers problem?

A.0
B.1 ✅
C.n (number of readers)
D.-1
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: The `rw_mutex` semaphore is initialized to 1. It functions as a mutual exclusion semaphore for writers and also controls the access of the first and last reader to the critical section, ensuring that only one writer or the first/last reader performs the necessary operations.

Q8. What is the purpose of the `mutex` semaphore in the readers-writers solution?

A.To provide mutual exclusion for writers
B.To control access for readers
C.To ensure mutual exclusion when updating the `read_count` variable ✅
D.To synchronize all reader and writer processes
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: The `mutex` semaphore is used to protect the critical section where the `read_count` variable is updated. As multiple readers can concurrently increment or decrement this variable, `mutex` ensures that these updates are atomic and do not lead to race conditions.

Q9. What does the `read_count` variable keep track of in the readers-writers solution?

A.The total number of writers waiting
B.The number of processes currently reading the object ✅
C.The number of times a reader has accessed the database
D.The total number of items in the database
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: `read_count` tracks how many processes are currently engaged in reading the shared database. This count is crucial for deciding whether the current reader is the first or last, which determines when to acquire or release the `rw_mutex` semaphore.

Q10. If a writer is in the critical section and 5 readers are waiting, how are the readers queued?

A.All 5 readers are queued on `rw_mutex`
B.1 reader is queued on `rw_mutex` and 4 readers are queued on `mutex` ✅
C.All 5 readers are queued on `mutex`
D.2 readers are queued on `rw_mutex` and 3 on `mutex`
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: When a writer holds the `rw_mutex`, the first waiting reader blocks on `rw_mutex`. The subsequent readers block on `mutex` because they are waiting to increment `read_count`. This organization ensures that once the writer releases `rw_mutex`, the first reader can proceed, allowing all waiting readers to enter.

Q11. What happens when a writer executes `signal(rw_mutex)` in the first readers-writers solution?

A.It may resume either the waiting readers or a single waiting writer ✅
B.It only resumes waiting readers
C.It only resumes a waiting writer
D.It does not resume any process
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: The `signal(rw_mutex)` operation allows the scheduler to choose which process to wake up. It could be one of the waiting readers (if there are multiple) or a single waiting writer. This introduces a scheduling decision that is not controlled by the synchronization solution itself.

Q12. What is a potential consequence of the first readers-writers problem?

A.Readers may starve
B.Writers may starve ✅
C.Both readers and writers may starve
D.Neither readers nor writers may starve
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: The first readers-writers problem gives priority to readers. This can lead to writer starvation, as a continuous stream of readers could prevent a waiting writer from ever acquiring the `rw_mutex` lock and gaining exclusive access to the database.

Q13. What is a potential consequence of the second readers-writers problem?

A.Readers may starve ✅
B.Writers may starve
C.Both readers and writers may starve
D.Neither readers nor writers may starve
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: The second readers-writers problem gives priority to writers. This can lead to reader starvation, as a continuous stream of writers could prevent waiting readers from ever starting their reading operations. The writers' priority allows them to be scheduled as soon as they are ready.

Q14. In the reader process code, why is `wait(rw_mutex)` called only when `read_count` becomes 1?

A.To ensure only the first reader acquires the lock
B.To allow multiple readers to read simultaneously
C.To prevent writers from accessing the database
D.All of the above ✅
💡 Difficulty: medium | ✅ Correct: D

📖 Explanation: The first reader must acquire `rw_mutex` to block any potential writers from entering. Subsequent readers do not need to acquire it, allowing them to read concurrently. This also prevents writers from accessing the database while any readers are active, as the lock is held until the last reader releases it.

Q15. In the reader process code, why is `signal(rw_mutex)` called only when `read_count` becomes 0?

A.To ensure the last reader releases the lock
B.To allow the first waiting writer or readers to proceed
C.To signal that no readers are currently active
D.All of the above ✅
💡 Difficulty: medium | ✅ Correct: D

📖 Explanation: The `rw_mutex` lock is held as long as there is at least one reader active. Only when the count drops to 0 (the last reader exits) is the lock released. This signals that the database is free, allowing a waiting writer or a new batch of readers to acquire the lock and proceed.

Q16. A reader-writer lock is a generalization of the readers-writers problem. When a process requests this lock in read mode, what access is granted?

A.Exclusive access for writing
B.Shared access with other readers ✅
C.Exclusive access for reading
D.Shared access with both readers and writers
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: A reader-writer lock in read mode allows multiple processes to concurrently acquire the lock for reading. This provides shared access to the data, as simultaneous reads do not cause any data integrity issues. The lock ensures that no writer can acquire it while readers hold it in read mode.

Q17. What is the primary advantage of using reader-writer locks over simple semaphores?

A.They are less complex to implement
B.They provide increased concurrency by allowing multiple readers ✅
C.They require less overhead
D.They guarantee no starvation
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Reader-writer locks increase concurrency by permitting multiple readers to access the shared data simultaneously. While semaphores can also be used to solve the problem, reader-writer locks provide a more specialized and efficient mechanism when the application has many readers and few writers.

Q18. When is a reader-writer lock most useful?

A.In applications with many writers and few readers
B.In applications where it is easy to identify readers and writers ✅
C.In applications where all processes need exclusive access
D.In applications with an equal number of readers and writers
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Reader-writer locks are most useful when it is clear which processes only read and which only write. This allows the system to grant shared read access or exclusive write access appropriately, maximizing concurrency without compromising data integrity.

Q19. What is a disadvantage of using reader-writer locks?

A.They cause more data inconsistency
B.They generally require more overhead than semaphores ✅
C.They only support one reader at a time
D.They cannot be used with multiple processes
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Reader-writer locks generally have higher overhead than simpler synchronization mechanisms like semaphores or mutexes. This is due to the added complexity of managing read and write modes. This overhead is justified when the increased concurrency from multiple readers compensates for it.

Q20. In the second readers-writers problem, once a writer is ready to write, what happens to new readers?

A.They may start reading immediately
B.They are not allowed to start reading ✅
C.They are given priority over the writer
D.They are queued behind the writer but can still proceed
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: The second readers-writers problem prioritizes writers. Once a writer is ready and waiting, no new readers are permitted to start reading. This ensures that the writer can perform its write operation as soon as possible, without being delayed by a constant influx of new readers.

Q21. In the solution to the first readers-writers problem, the semaphore `rw_mutex` is used for:

A.Mutual exclusion among writers and the first/last reader ✅
B.Counting the number of active readers
C.Synchronizing all readers and writers
D.Tracking the number of waiting writers
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: `rw_mutex` serves a dual purpose: it provides mutual exclusion for writers (ensuring only one writer writes at a time), and it is used by the first reader to acquire the lock and by the last reader to release it. This effectively manages the transition between read and write modes.

Q22. Which of the following is a correct statement about the `mutex` semaphore in the readers-writers solution?

A.It is used to lock the entire database
B.It is only used by writer processes
C.It protects the critical section for `read_count` updates ✅
D.It is not a semaphore but an integer variable
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: The `mutex` semaphore's only role is to ensure atomic updates to the `read_count` variable. Since multiple readers can try to increment or decrement this count simultaneously, `mutex` is necessary to prevent race conditions and maintain a correct count of active readers.

Q23. The first readers-writers problem is also known as what type of priority problem?

A.Writer-priority
B.Reader-priority ✅
C.No priority
D.Mutual priority
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: The first readers-writers problem is often called the reader-priority problem because it favors readers. It ensures that readers are not kept waiting by writers, allowing them to access the database as long as no writer is actively writing.

Q24. The second readers-writers problem is also known as what type of priority problem?

A.Writer-priority ✅
B.Reader-priority
C.No priority
D.Mutual priority
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: The second readers-writers problem is known as the writer-priority problem. It prioritizes writers over readers, ensuring that once a writer is ready, it can write as soon as possible, even if that means delaying new readers from starting.

Q25. In the reader process, after the reading is performed, what is the first operation performed?

A.signal(mutex)
B.wait(mutex) ✅
C.signal(rw_mutex)
D.wait(rw_mutex)
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: After reading is completed, the reader must decrement `read_count`. Before modifying `read_count`, it must acquire the `mutex` lock to ensure exclusive access to this shared variable. The first operation is therefore `wait(mutex)` to enter the critical section protecting `read_count`.

Q26. In the reader process, the code checks `if (read_count == 1)` after incrementing the count. This condition indicates that:

A.The current reader is the last reader
B.The current reader is the first reader ✅
C.A writer is waiting
D.Another reader is already reading
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: After the reader has incremented `read_count`, if the value is 1, it means no other reader was active before this one. The current reader is the first to enter the critical section. It must therefore acquire the `rw_mutex` lock to prevent writers from accessing the database.

Q27. In the reader process, the code checks `if (read_count == 0)` after decrementing the count. This condition indicates that:

A.The current reader is the first reader
B.Another reader is still reading
C.The current reader is the last reader ✅
D.A writer is waiting
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: After the reader has decremented `read_count`, if the value is 0, it means this reader was the last active reader. Therefore, it must release the `rw_mutex` lock by executing `signal(rw_mutex)`, allowing any waiting writers or a new batch of readers to access the database.

Q28. What is the primary difference between the first and second readers-writers problems?

A.The number of readers allowed
B.The priority given to readers versus writers ✅
C.The use of semaphores
D.The size of the database
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: The fundamental difference lies in the priority scheme. The first problem prioritizes readers (reader-priority), where no reader waits for a writer. The second problem prioritizes writers (writer-priority), where no new reader can start if a writer is waiting. This priority difference leads to different starvation scenarios.

Q29. A system uses the first readers-writers solution. A writer is waiting to write, and a steady stream of readers arrives. What is likely to happen?

A.The writer will eventually write after the current readers finish
B.The writer may starve indefinitely ✅
C.The readers will be blocked
D.The system will deadlock
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: In the first readers-writers problem, readers have priority. If readers continuously arrive, the `read_count` will never drop to 0. This means the `rw_mutex` lock is never released, and the waiting writer can be starved indefinitely, as it never gains exclusive access to the database.

Q30. A system uses the second readers-writers solution. A writer is ready to write, and new readers arrive. What is the status of the new readers?

A.They can start reading immediately
B.They are blocked until the writer finishes ✅
C.They are allowed to finish reading but then blocked
D.They are given priority over the writer
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: In the second readers-writers problem, once a writer is ready, no new readers may start. The writer is given priority, so any new readers that arrive will be blocked and must wait until the writer has completed its write operation, even if no readers are currently active.

Q31. Which of the following is a correct statement about the `rw_mutex` semaphore in the readers-writers solution?

A.It is a counting semaphore
B.It is initialized to the number of readers
C.It is used by all readers to enter the critical section
D.It is not used by readers who enter or exit while other readers are in their critical sections ✅
💡 Difficulty: hard | ✅ Correct: D

📖 Explanation: `rw_mutex` is only used by the first reader to acquire the lock and the last reader to release it. Readers that enter or exit when other readers are already active do not interact with `rw_mutex`. This design allows multiple readers to read concurrently without blocking on each other.

Q32. In the first readers-writers problem, if a writer is in the critical section, and multiple readers are waiting, what is the queueing arrangement?

A.All readers are queued on the `mutex` semaphore
B.All readers are queued on the `rw_mutex` semaphore
C.One reader is queued on `rw_mutex`, and the rest are queued on `mutex` ✅
D.The readers are split equally between `mutex` and `rw_mutex`
💡 Difficulty: hard | ✅ Correct: C

📖 Explanation: When a writer holds `rw_mutex`, the first waiting reader will block on `rw_mutex`. The subsequent readers will block on `mutex` because they are waiting to update `read_count`. This hierarchical queuing prevents all readers from blocking on the same semaphore and ensures the first reader can proceed once the writer is done.

Q33. What is the role of the `mutex` semaphore in the writer's code?

A.It is used to ensure exclusive access for the writer
B.It is not used in the writer's code ✅
C.It is used to update the `read_count`
D.It is used to synchronize with other writers
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: In the standard solution to the first readers-writers problem, the writer's code does not use the `mutex` semaphore. The writer only interacts with `rw_mutex` to gain exclusive access to the database. The `mutex` semaphore is solely used by readers to protect the `read_count` variable.

Q34. When a reader-writer lock is acquired in write mode, what type of access does the process get?

A.Shared access with other readers
B.Shared access with other writers
C.Exclusive access for writing ✅
D.Exclusive access for reading
💡 Difficulty: hard | ✅ Correct: C

📖 Explanation: A reader-writer lock in write mode provides exclusive access. Only one process can hold the lock for writing at a time, and no other process (reader or writer) can access the data concurrently. This ensures complete data integrity during write operations.

Q35. When a reader-writer lock is acquired in read mode, what type of access does the process get?

A.Exclusive access for reading
B.Shared access with other readers ✅
C.Exclusive access for writing
D.Shared access with both readers and writers
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: A reader-writer lock in read mode allows shared access. Multiple processes can concurrently acquire the lock for reading. This is safe because simultaneous reads do not modify data and thus cannot cause conflicts or corruption.

Q36. Reader-writer locks are most useful in applications that have:

A.More writers than readers
B.More readers than writers ✅
C.An equal number of readers and writers
D.No writers
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: Reader-writer locks are most beneficial when there are significantly more readers than writers. The increased concurrency from allowing multiple readers to access the data simultaneously compensates for the higher overhead of setting up and managing the lock. In writer-heavy applications, the overhead may not be justified.

Q37. What is the main drawback of using reader-writer locks compared to simple mutual-exclusion locks?

A.They provide less concurrency
B.They are more complex and have higher overhead ✅
C.They cause more data inconsistency
D.They cannot be used in multi-threaded applications
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: The main drawback is the increased complexity and overhead. Reader-writer locks must manage two modes of access (read and write), which requires more internal bookkeeping. This overhead is acceptable when the concurrency benefits from multiple readers outweigh the cost.

Q38. In the reader process, why is `signal(mutex)` executed immediately after incrementing `read_count`?

A.To release the lock on the entire database
B.To release the lock on `read_count` so other readers can increment it ✅
C.To allow a writer to enter
D.To signal that the reader has finished reading
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: `wait(mutex)` is used to protect the critical section where `read_count` is updated. Once the increment is done and the `rw_mutex` lock is possibly acquired, the `mutex` lock must be released. This allows other readers to enter their critical sections and update `read_count` concurrently, enabling multiple readers to coexist.

Q39. In the reader process, why is `wait(mutex)` executed before decrementing `read_count`?

A.To lock the entire database
B.To allow a writer to enter
C.To ensure exclusive access to the critical section of `read_count` ✅
D.To signal that the reader has finished reading
💡 Difficulty: hard | ✅ Correct: C

📖 Explanation: Before modifying `read_count` (decrementing it), the reader must acquire the `mutex` lock. This ensures that the decrement operation is atomic and that the count remains accurate. Multiple readers may be decrementing the count simultaneously, so mutual exclusion on `read_count` is essential.

Q40. If `read_count` is 3, and a reader is about to finish reading, how many readers are still reading just after it executes `read_count--`?

A.2 ✅
B.3
C.1
D.0
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: If `read_count` was 3 before the decrement, it means 3 readers were active. After the decrement, the value becomes 2. This indicates that there are still 2 readers reading the database. The `signal(rw_mutex)` will only be executed if the new value of `read_count` is 0 (i.e., the current reader was the last one).

Q41. The readers-writers problem is used to test nearly every new synchronization primitive because it:

A.Is the most complex synchronization problem
B.Highlights the challenges of managing concurrent access with different requirements (reading vs. writing) ✅
C.Is the only problem that requires semaphores
D.Has a simple and well-understood solution
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: The problem is a benchmark because it encapsulates a fundamental concurrency challenge: managing access to a shared resource where some processes only read (which can be concurrent) and others write (which require exclusive access). This duality makes it an excellent test case for any new synchronization mechanism.

Q42. In the first readers-writers problem, if a writer is executing `wait(rw_mutex)` and a reader is currently reading, what happens?

A.The writer continues to execute
B.The writer is blocked ✅
C.The reader is blocked
D.A deadlock occurs
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: If a reader is currently active and holding the `rw_mutex` lock, a writer calling `wait(rw_mutex)` will be blocked. The writer must wait until all readers have finished and the last reader has executed `signal(rw_mutex)` to release the lock. The readers are given priority in this scenario.

Q43. If `read_count` is 0, and a writer finishes writing and executes `signal(rw_mutex)`, what are the possible processes that can be scheduled to run next?

A.Only a waiting reader
B.Only a waiting writer
C.Either a waiting reader or a single waiting writer ✅
D.No process will be unblocked
💡 Difficulty: hard | ✅ Correct: C

📖 Explanation: The `signal(rw_mutex)` operation will wake up a process waiting on that semaphore. Depending on the system's scheduling policy, the scheduler could choose to resume either a waiting reader (or a group of them, one by one) or a single waiting writer. The synchronization solution itself does not dictate which one is chosen.

Q44. A reader-writer lock is requested in write mode, and several readers currently hold the lock in read mode. What happens?

A.The writer is granted the lock immediately
B.The writer is blocked until all readers release the lock ✅
C.The writer is given priority and the readers are preempted
D.The readers are blocked and the writer proceeds
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: When a writer requests a lock in write mode, it must wait for exclusive access. If readers currently hold the lock, the writer will block until all those readers have released their read locks. This ensures data consistency, as a writer cannot modify data while readers are reading potentially inconsistent states.

Q45. What is the primary purpose of requiring writers to have exclusive access in the readers-writers problem?

A.To speed up the writing process
B.To prevent data corruption and ensure consistency ✅
C.To reduce the number of readers
D.To simplify the synchronization code
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: The entire problem is motivated by the need to maintain data integrity. If a writer and another process accessed the database simultaneously, the data could become corrupted or inconsistent. Exclusive access ensures that write operations are atomic and the database's state remains correct.

Q46. In the first readers-writers problem, which semaphore is shared between both reader and writer processes?

A.`mutex`
B.`rw_mutex` ✅
C.Both `mutex` and `rw_mutex`
D.`read_count`
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: The `rw_mutex` semaphore is common to both reader and writer processes. It provides mutual exclusion for writers and controls the access of the first and last reader to the critical section. The `mutex` semaphore is exclusively used by readers to protect the `read_count` variable.

Q47. In the second readers-writers problem, why might readers starve?

A.Because writers are given priority and can continuously hold the lock ✅
B.Because readers are not allowed to hold the lock for too long
C.Because `read_count` is not updated correctly
D.Because `rw_mutex` is not used correctly
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: In the writer-priority variant, once a writer is ready, no new readers can start. If there is a continuous stream of writers, readers can be starved of access to the database. They may wait indefinitely for their turn to read while writers repeatedly acquire and release the lock.

Q48. Which of the following statements about starvation in the readers-writers problem is TRUE?

A.Starvation is not possible in either the first or second problem
B.Starvation is possible in both the first and second problems ✅
C.Starvation is only possible in the first problem
D.Starvation is only possible in the second problem
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: Starvation is a known issue in both classic variants. The first problem (reader-priority) can lead to writer starvation. The second problem (writer-priority) can lead to reader starvation. This is why other, more complex variants that avoid starvation have been proposed.

Q49. Consider a system using the first readers-writers solution. There are 2 active readers. A writer arrives and waits. A new reader arrives. What happens to the new reader?

A.The new reader is blocked on `mutex`
B.The new reader can start reading immediately ✅
C.The new reader is blocked on `rw_mutex`
D.The new reader is granted priority over the writer
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: Since there are already active readers (`read_count > 0`), a new reader can start reading immediately. It will increment `read_count` and, because it is not the first reader, it will not interact with `rw_mutex`. The writer remains blocked, as the readers are given priority. This scenario illustrates how writers can starve.

Q50. Consider a system using the second readers-writers solution. There are 2 active readers. A writer arrives and waits. A new reader arrives. What happens to the new reader?

A.The new reader can start reading immediately
B.The new reader is blocked ✅
C.The new reader is given priority over the writer
D.The new reader is queued on `mutex`
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: In the writer-priority variant, once a writer is waiting, no new readers are allowed to start. The new reader is blocked and must wait for the writer to finish its write operation. This ensures that the writer can proceed as soon as possible, even if it means delaying the arrival of new readers.

Q51. Why is `read_count` initialized to 0 in the readers-writers solution?

A.Because no writers are initially active
B.Because no readers are initially reading ✅
C.Because the database is empty
D.Because `rw_mutex` is initialized to 1
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: `read_count` tracks the number of active readers. Initially, no process is reading the database, so the count is 0. This initial value is essential for the logic of the first reader, which must acquire `rw_mutex`, and the last reader, which must release it. A non-zero initial value would break this logic.

Q52. In the context of reader-writer locks, what is the term for a lock that can be acquired in either read or write mode?

A.Semaphore
B.Mutex
C.Reader-writer lock ✅
D.Condition variable
💡 Difficulty: hard | ✅ Correct: C

📖 Explanation: A reader-writer lock is a specific type of lock that allows processes to specify the mode of access. This lock can be acquired in read mode for shared read access or in write mode for exclusive write access. It is a generalization of the readers-writers problem's synchronization requirements.

Q53. Which of the following is NOT a situation where reader-writer locks are most useful?

A.Applications where it is easy to identify readers and writers
B.Applications with many more readers than writers
C.Applications with many more writers than readers ✅
D.Applications where concurrency for reading is important
💡 Difficulty: hard | ✅ Correct: C

📖 Explanation: Reader-writer locks are less useful in writer-heavy applications. In such cases, the lock will frequently be acquired in write mode (which provides exclusive access), negating the concurrency benefit of allowing multiple readers. The overhead of the lock may not be justified when few reads are happening.

Q54. In the first readers-writers problem, what is the significance of the reader executing `wait(rw_mutex)` only when it is the first reader?

A.It ensures that writers cannot write while any reader is reading ✅
B.It allows the reader to modify the database
C.It grants the reader exclusive access
D.It prevents other readers from reading
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: The purpose of the first reader acquiring `rw_mutex` is to block any writers from accessing the database while at least one reader is active. Since writers require exclusive access, the `rw_mutex` lock held by the first reader acts as a barrier, preventing writers from entering the critical section. The lock is held until the last reader leaves.

Q55. In the first readers-writers problem, what is the significance of the last reader executing `signal(rw_mutex)`?

A.It allows the reader to finish reading
B.It releases the lock, allowing a writer or a new batch of readers to proceed ✅
C.It signals the end of all reading operations
D.It releases the `mutex` lock
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: The last reader releases the `rw_mutex` lock to indicate that no readers are currently active. This unblocks any waiting writers or allows the first of a new batch of readers to acquire the lock and start reading. This signal is the crucial transition point between read and write modes.

🔗 Related Topics (MCQs)