DSA Factory
Free Synchronization lessonsSynchronization · Stage 2 · The classic problems · Step 2

Readers and writers

Allow many readers or one writer, and see how a simple preference rule can starve the other side. About 12 minutes.

Quick check

What can go wrong with a readers-writers lock that always lets new readers in while others are reading?

  1. AA waiting writer can starve if readers keep overlapping
  2. BReaders can corrupt the data
  3. CIt always deadlocks
Show the answer

A waiting writer can starve if readers keep overlapping. The reader count never drops to zero, so the writer never gets exclusive access.

Lock it in

4 questions on this idea

Short questions that apply the idea to new cases: trace it, work out a number, put steps in order. A wrong answer explains itself.

Answer them in your browserFree account, no card. Your progress is saved, and the idea comes back in a quick review later.
Sign up free to solve