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).
Practice this topic Back to topic

More Multicore & Synchronization questions

  1. What is the most suitable use of a counting semaphore?
  2. What is the difference between cache coherence and a memory consistency model?
  3. Which describes the idea of hardware transactional memory?
  4. When waiting on a condition variable until a queue becomes non-empty, why is the condition rechecked in a while loop rather than an if after waking?
  5. Two cores each hold a copy of variable x in their own caches. After core 0 writes x, what problem could occur when core 1 reads x if there were no cache coherence mechanism?