Multicore & Synchronization

What is a characteristic of a reader-writer lock?

  1. AAny number of writers may enter together, but only one reader
  2. BAny number of readers may enter together, but a writer enters alone, excluding everyone else
  3. COnly one thread may enter, whether reading or writing
Show answer and explanation

Answer: B. Any number of readers may enter together, but a writer enters alone, excluding everyone else

Concurrent reads cannot corrupt data, so a reader-writer lock lets readers run together and makes only writers exclusive. It raises parallelism for data that is read often and changed rarely, such as a configuration table. If readers keep arriving, though, a writer may never get in, so some implementations give writers priority.

  • A. It is the other way around.
  • B. Correct. It suits data that is mostly read.
  • C. That is an ordinary lock (mutex).