🎓 BookMCQ
← Back to 5. Process Synchronization

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

Concurrent Reading and Exclusive Writing of Shared Data

The readers-writers problem concerns synchronization when multiple processes or threads share a data object that supports both reading and writing. Multiple readers may access the data simultaneously because they do not modify it, but a writer requires exclusive access to prevent inconsistent updates. Different readers-writers algorithms establish priorities between readers and writers to control access and waiting behaviour.

Why Reading Can Be Shared but Writing Requires Exclusion

Allowing every access to occur under exclusive locking prevents conflicting updates but unnecessarily restricts simultaneous reading. Conversely, permitting reading and writing together can expose incomplete or inconsistent data. The synchronization design must therefore allow compatible read operations to overlap while preventing writers from modifying the object during active reads or competing writes.

Reader Counts, Writer Locks, and Admission Policies

A common semaphore solution maintains a reader count protected by a mutex. The first reader acquires a shared resource semaphore, preventing writers from entering; subsequent readers join without repeating that acquisition. When the last reader exits, it releases the resource semaphore. Writers acquire the resource semaphore exclusively before updating the shared data.

Three Readers Competing with One Writer

Suppose readers R1, R2, and R3 access a shared database record while writer W requests an update. The readers may proceed together if the policy permits concurrent reading. W must wait until the active readers finish. After the final reader releases the resource, W obtains exclusive access and completes its modification.

Reader Throughput, Writer Starvation, and Fairness

Readers-writers synchronization improves throughput for read-intensive workloads such as databases and shared configuration services. Reader-preference solutions may starve writers when new readers continually arrive. Writer-preference policies reduce writer delays but may postpone readers. Fair solutions attempt to balance both groups, although queue management and workload patterns influence actual performance.

Misconceptions About Reader and Writer Access

'Readers always require exclusive access' is incorrect because compatible readers can share access. 'A writer can safely modify data while readers are active' is incorrect because readers may observe inconsistent state. 'Every readers-writers solution guarantees equal waiting time' is incorrect because fairness depends on the admission policy.

Exam Focus: Comparing Readers-Writers Synchronization Policies

Trace reader-count changes and identify when the first reader acquires and the last reader releases the resource lock. Compare reader-preference, writer-preference, and fair approaches. Questions may examine simultaneous reading, exclusive writing, semaphore ordering, starvation, and how continuous arrivals from one group affect waiting in the other group.

Key Terms of the Readers-Writers Problem

  • Reader - Process accessing data without modification.
  • Writer - Process modifying shared data.
  • Reader count - Number of active readers.
  • Writer preference - Policy prioritising waiting writers.
  • Reader preference - Policy favouring reader admission.
  • Fairness - Balanced opportunity for access.
12
Easy
12
Medium
12
Hard

📝 All The Readers Writers Problem in Process Synchronization MCQs

Q1. A shared configuration database serves many queries and occasional updates. Which access rule preserves correctness while allowing compatible work to overlap?

A.Readers may share access; each writer must exclude all readers and other writers ✅
B.Readers and writers may overlap when they access different fields
C.Only writers may execute concurrently; readers require exclusive access
D.Readers need no coordination because they never modify the database
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: Read-only operations can safely overlap, but a modification must be isolated from every other access to preserve a consistent state. The rule permits reader concurrency while making writer access exclusive.

Q2. Two analytics threads read the same immutable table while no update is running. Why can a correct readers-writers design admit both at once?

A.A reader automatically owns the resource semaphore for all other readers
B.Their operations do not alter the shared table, so neither can expose the other to a partial update ✅
C.The scheduler guarantees that their instructions will never interleave
D.Simultaneous readers are safe only when they have different process identifiers
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: Both operations only inspect unchanged data, so their execution does not create conflicting modifications. The synchronization rule can therefore share the read mode without weakening the exclusion required for writers.

Q3. A shared inventory service has two update requests. What must be true while the first writer holds the protected resource?

A.Readers may enter if the first writer is temporarily preempted
B.The second writer may update a different field without coordination
C.No reader or second writer may access the protected object ✅
D.Readers may enter after the first half of the update is complete
💡 Difficulty: easy | ✅ Correct: C

📖 Explanation: A writer must have exclusive access for the entire protected update. Preemption does not release ownership, and splitting the update into fields does not authorize overlapping access unless those fields use independent protection.

Q4. A financial record stores balance and transaction_count. A reader sees the old balance but the new transaction_count during an update. What has gone wrong?

A.The reader count was incremented too early
B.The writer was granted too much priority
C.The reader acquired two shared locks
D.The reader observed a mixed state because reading overlapped a multi-field write ✅
💡 Difficulty: easy | ✅ Correct: D

📖 Explanation: The two fields form one logical state, so observing them across different stages of a write can violate the application invariant. Exclusive writer access must prevent readers from seeing intermediate combinations.

Q5. A monitoring operation reads a database row but also increments a shared global statistics counter. How should its synchronization needs be classified?

A.The counter update is a write and requires protection against concurrent updates ✅
B.The entire operation is a pure read because its main purpose is monitoring
C.The counter can be modified concurrently because increments are always indivisible
D.No synchronization is needed when the data row itself is unchanged
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: Although the row access is read-only, incrementing a shared counter modifies shared state. Concurrent increments can be lost unless protected, so the operation needs write-style coordination for that counter to remain correct.

Q6. A writer owns an exclusive lock and is descheduled for 8 milliseconds. A reader arrives during that interval. What is the correct action?

A.Allow the reader to proceed because the writer is not currently running
B.Keep the reader blocked until the writer releases the lock ✅
C.Let the reader proceed if it has a higher scheduling priority
D.Convert the writer lock into a shared lock during preemption
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: Lock ownership persists while a task is descheduled. Allowing a reader into the protected object would overlap with the unfinished write, so the reader must wait for an explicit release.

Q7. In a reader-preference semaphore solution, read_count starts at zero. Reader R1 enters alone. Which sequence is required?

A.Acquire the resource semaphore, then increment the count only after reading
B.Increment read_count and acquire the resource semaphore for every reader
C.Increment read_count, then acquire the resource semaphore only because the count changed from zero to one ✅
D.Leave read_count unchanged until the final reader exits
💡 Difficulty: easy | ✅ Correct: C

📖 Explanation: The first reader closes the resource to writers by acquiring its semaphore. Later readers join the active group without acquiring it again, while the count records how many readers must finish before release.

Q8. A reader-count mutex protects read_count. R1 and R2 both enter, making the count two. R1 exits first. What should the protocol do?

A.Release the resource semaphore because R1 has finished
B.Set read_count to zero because one reader has left
C.Acquire the resource semaphore a second time for R2
D.Decrement the count to one and keep the resource semaphore held ✅
💡 Difficulty: easy | ✅ Correct: D

📖 Explanation: R2 remains active after R1 exits, so a writer must still be excluded. The count becomes one, and only the transition from one active reader to zero releases the shared resource semaphore.

Q9. In a correct first-reader/last-reader protocol, read_count is three. Two readers finish one after another. What is the count after both exits, and is the resource available to a writer?

A.The count is one, and the resource remains held by the reader group ✅
B.The count is zero, and the resource is available
C.The count is two, and the resource remains held
D.The count is one, and the resource is available
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: Each completed reader decrements the protected count once. Starting from three, two exits leave one active reader, so the last-reader condition has not occurred and the writer must continue waiting.

Q10. A student releases the database semaphore whenever any reader exits. Which correction fixes the protocol?

A.Release it only when a reader enters
B.Release it only when the count changes from one to zero ✅
C.Release it whenever read_count is greater than zero
D.Release it after every decrement, then reacquire it for remaining readers
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: The flawed step releases the resource while other readers may still be using it. The correct condition is the last reader transition, when the protected count falls from one to zero.

Q11. The following observations are recorded: time 0 has 2 active readers; time 1 has 3; time 2 has 2; time 3 has 1; time 4 has 0; time 5 has 0. A writer has waited since time 1. At what earliest listed time can it acquire the resource, assuming no other request wins first?

A.Time 2
B.Time 3
C.Time 4 ✅
D.Time 5 only
💡 Difficulty: easy | ✅ Correct: C

📖 Explanation: The writer needs the active-reader count to reach zero. The listed counts remain positive through time 3 and first become zero at time 4, which is the earliest point when reader activity no longer blocks it.

Q12. Two readers update read_count without holding its protecting mutex. Both read the value 4, each computes 5, and each stores 5. What is the resulting defect?

A.The count becomes six because both updates are automatically combined
B.The resource semaphore is released twice
C.The count becomes zero because both readers overwrite it
D.A lost update leaves the count at five instead of six ✅
💡 Difficulty: easy | ✅ Correct: D

📖 Explanation: Both readers use the same stale value and store the same incremented result. One increment is lost, so the count underreports active readers and can cause premature release of the resource semaphore.

Q13. Which policy best matches the first readers-writers problem?

A.A reader may join other readers even when a writer is waiting, provided no writer has acquired access ✅
B.A waiting writer blocks every reader immediately
C.Only one reader may use the object at a time
D.A writer and readers may access the object together when the writer is preempted
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: Reader preference allows new readers to join an existing reader group rather than waiting merely because a writer is queued. This improves reader access but can keep writers waiting for a long time.

Q14. A library service uses writer preference: as soon as a writer waits, new readers are stopped from entering. Which risk does this policy reduce most directly?

A.A reader observing a partially completed write after entering late
B.A writer waiting indefinitely behind a continuous stream of newly admitted readers ✅
C.Two readers accessing the resource at the same time
D.A writer releasing the resource semaphore after finishing
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Closing reader admission when a writer queues prevents later readers from extending the active group indefinitely. Existing readers finish, after which the writer can obtain exclusive access, reducing writer starvation risk.

Q15. A reader-preference database admits new readers whenever at least one reader is active. Readers keep arriving so the active count never reaches zero. What can happen to a waiting writer?

A.It must enter after the first reader exits
B.It can write alongside the active readers if its priority is high
C.It may starve even though readers continue making progress ✅
D.The whole system is necessarily deadlocked
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: The writer needs the reader group to drain completely. Continuous reader admission can prevent the count from reaching zero, so the writer may wait without bound while readers continue completing work.

Q16. A strict writer-preference policy repeatedly serves waiting writers before admitting new readers. If writers continue to arrive, what risk may readers face?

A.Writers may observe stale data
B.The reader count must increase without limit
C.Two writers must enter together
D.Readers may starve because writer requests keep taking precedence ✅
💡 Difficulty: medium | ✅ Correct: D

📖 Explanation: Writer preference protects waiting writers by delaying new readers, but sustained writer arrivals can repeatedly postpone reader admission. Mutual exclusion may remain correct even while readers experience starvation under sustained arrivals.

Q17. A trace shows readers completing continuously while one writer remains blocked and no writer owns the resource. How should this situation be classified?

A.Starvation of the writer, not necessarily deadlock ✅
B.Deadlock, because any blocked process proves deadlock
C.Mutual exclusion failure, because readers are progressing
D.A race condition that guarantees data corruption
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: Progress by readers shows that the system is not globally stuck. The writer is being bypassed indefinitely by the admission policy, which is starvation rather than proof of deadlock by itself.

Q18. A design intends to give writers priority, but it checks waiting_writers and then admits a reader without protecting the check and admission as one operation. What is the main flaw?

A.A writer can arrive after the check but before the reader enters, allowing the reader to bypass it
B.The reader count will always be negative ✅
C.The resource becomes permanently unavailable to writers
D.Every reader will acquire the exclusive lock twice
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: The separate check and admission create a race window. A writer can queue after the reader sees no waiting writers, yet before it enters, defeating the intended priority rule unless admission is coordinated atomically.

Q19. An application changes from read-heavy traffic to frequent writes. Which conclusion is most justified before changing its lock policy?

A.Reader preference must still be optimal because reads once dominated
B.Exclusive access should be removed to increase write throughput
C.Measure writer latency and starvation under the new workload, then consider writer-aware or fair admission ✅
D.Set read_count to a fixed value to reserve writer time
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: A policy that performed well under read-heavy traffic may delay writers under a changed workload. Measuring both throughput and wait times identifies whether a writer-aware or fair policy is warranted.

Q20. A system claims that its readers-writers lock is fair but provides no queueing rule or starvation guarantee. Which statement should be treated cautiously?

A.An active writer must exclude readers
B.Writers require exclusive access
C.Every waiting reader and writer will eventually acquire the lock
D.Concurrent shared reading may be supported ✅
💡 Difficulty: medium | ✅ Correct: D

📖 Explanation: Safety properties do not automatically establish fairness. Without a specified admission or queueing guarantee, a lock may favor one class under load, so eventual service for every waiter cannot be assumed.

Q21. A fair turnstile is used by both reader and writer arrivals. What is its main role?

A.To serialize admission decisions so later arrivals cannot continually overtake an earlier waiter ✅
B.To make each reader exclusive
C.To replace the resource lock during writing
D.To increase read_count whenever a writer arrives
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: A common admission point can preserve arrival order or a defined queueing rule. It limits overtaking by later requests, while a separate resource mechanism still enforces concurrent-reader and exclusive-writer access.

Q22. A fair queue contains R1, then W1, then R2 and R3. R1 finishes. Under FIFO admission with consecutive readers allowed as a group, who should be admitted next?

A.R2 and R3 before W1 because readers can always bypass writers
B.W1, because it is the first waiting request ✅
C.R3 alone because it arrived last
D.No process until the queue becomes empty
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: FIFO admission honors the earliest waiting request. Since W1 is ahead of R2 and R3, it receives the next exclusive turn after R1 finishes; later readers cannot overtake it in the queue.

Q23. A reader releases its shared lock and immediately requests it again. A writer is already queued in a fair system. What should determine whether the reader reenters?

A.The reader process identifier alone
B.The documented admission queue and fairness rule
C.The reader's prior ownership gives it permanent precedence ✅
D.The current value of the reader count without considering queued writers
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: Fairness depends on the lock's admission rule, not on a requester's previous ownership. A new read request should not automatically jump ahead of a writer already waiting in the queue.

Q24. A request timeline is recorded as follows: time 0, R1 enters; time 1, W1 queues; time 2, R2 queues; time 3, R3 queues; time 4, R1 exits. Under a fair FIFO policy, who is next?

A.R2
B.R3
C.A new reader arriving at time 4
D.W1 ✅
💡 Difficulty: medium | ✅ Correct: D

📖 Explanation: W1 entered the waiting queue before R2 and R3. A fair FIFO policy preserves that order, so once R1 releases the resource, W1 is next rather than a later reader.

Q25. A writer-priority implementation closes a reader gate when a writer begins waiting. Why must the gate be reopened after the relevant writers finish?

A.To prevent readers remaining blocked when no writer is waiting and the resource is available ✅
B.To reset active readers to zero even if they are still reading
C.To allow two writers to modify the resource together
D.To make reader count irrelevant to resource ownership
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: The gate should reflect the presence of waiting writers. Leaving it closed after the writer queue empties can block readers despite an available resource, producing unnecessary delay or a liveness defect.

Q26. The measured results for a proposed policy are: read throughput 900 operations/s; writer throughput 2 operations/s; maximum writer wait 40 seconds; occasional writer wait above 2 minutes. Which assessment is strongest?

A.The policy is optimal because read throughput is high
B.Read performance is strong, but writer delay suggests possible starvation and needs investigation ✅
C.The policy is fair because at least one writer completed
D.The measurements prove that readers and writers overlap incorrectly
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: High read throughput does not establish balanced service. Very long and growing writer waits may reveal reader bias, so fairness and tail latency should be assessed alongside aggregate throughput during sustained operation.

Q27. A service admits consecutive readers together but stops adding later readers when a writer reaches the front of the queue. Why is this useful?

A.It guarantees that every reader finishes before any writer arrives
B.It allows writes to overlap with the admitted reader group
C.It preserves useful read concurrency without letting an arriving stream postpone the queued writer forever ✅
D.It eliminates the need to count active readers
💡 Difficulty: hard | ✅ Correct: C

📖 Explanation: Grouping readers that are already ahead in the queue retains concurrency among compatible operations. Stopping later readers from extending the group lets the writer eventually receive its exclusive turn under ongoing arrivals.

Q28. A student updates read_count outside its mutex. Two readers each observe 6, add one, and store 7. Which correction is required?

A.Allow only one reader process to exist
B.Initialize read_count to one instead of zero
C.Have writers update read_count after each write
D.Protect the complete read-modify-write operation on read_count with its mutex ✅
💡 Difficulty: hard | ✅ Correct: D

📖 Explanation: The flawed step is the unprotected read-modify-write sequence, which loses one increment. The correct step is to hold the count mutex across reading, changing, and storing the shared value by every reader.

Q29. A reader-priority implementation allows every exiting reader to signal the resource semaphore. What is the likely consequence when three readers are active?

A.The resource can become available to a writer while two readers remain active ✅
B.The resource semaphore will always remain locked forever
C.The count is automatically corrected by the semaphore
D.Writers will be serialized more strictly than intended
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: The flawed step is signaling on every reader exit. The correct step is to release the resource only when the protected count reaches zero, ensuring no reader remains inside when a writer enters.

Q30. A writer checks that no readers are active, then pauses before acquiring exclusive access. A reader enters during the pause. Which design defect does this expose?

A.The reader should have waited for the writer to finish its computation
B.The check for zero readers and acquisition of exclusive access are not coordinated atomically ✅
C.The writer must acquire the reader-count mutex after writing
D.The system has too many reader processes
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: The flawed sequence separates checking availability from claiming the resource, allowing a reader to enter in between. The check and acquisition must be coordinated by the synchronization protocol to prevent overlapping access.

Q31. A read-mostly service records these points: reader arrival rate and mean writer wait are (1, 2), (2, 4), (3, 7), (4, 12), (5, 20), and (6, 31), where rate is requests per second and wait is seconds. What trend is shown?

A.Writer wait falls as reader arrivals increase
B.Writer wait remains constant across the workload
C.Writer wait rises increasingly quickly as reader arrivals increase ✅
D.The data proves that writers and readers access the resource concurrently
💡 Difficulty: hard | ✅ Correct: C

📖 Explanation: The wait values rise from 2 to 31 seconds as the arrival rate increases, with larger increments at higher rates. This pattern is consistent with growing writer delay under a reader-biased admission policy.

Q32. A reader holds a shared lock and requests an exclusive upgrade while another reader holds a shared lock and also requests an upgrade. What can happen in an implementation that retains both shared locks while waiting?

A.Both upgrades always succeed because the requests are identical
B.The lock becomes a writer-preference lock automatically
C.The readers may safely write at the same time
D.The system may deadlock because each upgrader waits for the other reader to release its shared lock ✅
💡 Difficulty: hard | ✅ Correct: D

📖 Explanation: Each upgrader retains a shared hold that prevents the other from obtaining exclusivity. If both wait without releasing or using atomic upgrade support, neither can proceed, creating a possible deadlock.

Q33. A database uses one global exclusive mutex for every query and update. Which change can improve read-heavy concurrency while preserving safe writes?

A.Replace it with a correctly implemented read-write lock that allows shared readers and exclusive writers ✅
B.Remove locking from all read operations, including reads that overlap writes
C.Allow each writer to acquire the mutex only after modifying the data
D.Use a separate reader count but never protect the count itself
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: A global mutex serializes even compatible reads. A read-write lock can admit multiple readers in shared mode while retaining exclusive writer access, provided its count and admission protocol are implemented correctly.

Q34. A shared service protects independent records. Two tasks access different records, while a third updates the same record as one of them. What is the main benefit and requirement of per-record locks?

A.They remove the need for synchronization because records are independent
B.They can increase concurrency across unrelated records but must still exclude conflicting access to each record ✅
C.They allow all writers to overlap, including writers of the same record
D.They require every task to lock every record before reading
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: Fine-grained locks reduce unnecessary contention between unrelated records. Each record still needs correct reader-writer exclusion, and operations spanning several records require a consistent lock ordering to avoid deadlock when operations share structures.

Q35. A trace begins with read_count = 0. R1 enters, R2 enters, R1 exits, R3 enters, R2 exits, and R3 exits. How many times should the first-reader/last-reader protocol acquire and release the resource semaphore?

A.Two acquisitions and two releases
B.Three acquisitions and one release
C.One acquisition and one release ✅
D.One acquisition and two releases
💡 Difficulty: hard | ✅ Correct: C

📖 Explanation: The count follows 0 to 1 to 2 to 1 to 2 to 1 to 0. Only the first transition acquires the resource semaphore and only the final transition releases it, giving one of each.

Q36. A writer-preference service has one active reader, one waiting writer, and three later readers. The active reader finishes. Which sequence best preserves the stated policy?

A.Admit all three later readers before the waiting writer
B.Allow the first later reader to enter because the resource is momentarily free
C.Allow the waiting writer and all readers to enter together
D.Admit the waiting writer before the later readers, then reconsider reader admission after the write ✅
💡 Difficulty: hard | ✅ Correct: D

📖 Explanation: Writer preference blocks new readers once a writer is waiting. When the active reader leaves, the queued writer should receive exclusive access before later readers, after which admission can be reconsidered.

🔗 Related Topics (MCQs)