Multicore & Synchronization

Which correctly compares coarse-grained locking (one lock for a whole large data structure) with fine-grained locking (separate locks for each part)?

  1. ACoarse-grained locking always gives more parallelism
  2. BFine-grained locking reduces the number of locks
  3. CFine-grained locking lets threads use different parts concurrently for more parallelism, but design is harder and deadlock risk grows
Show answer and explanation

Answer: C. Fine-grained locking lets threads use different parts concurrently for more parallelism, but design is harder and deadlock risk grows

A coarse lock is simple and hard to get wrong, but threads using unrelated parts still wait for each other, so adding cores helps little. Finer granularity, such as one lock per hash-table bucket, lets different parts be operated on simultaneously. But situations requiring several locks increase, and managing acquisition order and the overhead of the locks themselves become issues.

  • A. With a coarse lock, only one thread can enter at a time.
  • B. The number of locks increases.
  • C. Correct. The choice balances simplicity against parallelism.
Practice this topic Back to topic

More Multicore & Synchronization questions

  1. What property does a lock-free algorithm have?
  2. Which describes a critical section?
  3. Which describes barrier synchronization in parallel programs?
  4. When 64 cores continuously update one shared counter with atomic instructions, adding cores does not speed things up. What is the main reason?
  5. Which describes a NUMA (non-uniform memory access) system?