Multicore & Synchronization

Which describes a critical section?

  1. AA part of a program that operates on shared data and must be executed by only one thread at a time
  2. BThe part of a program that takes the longest time to run
  3. CA part that runs only when an error occurs
Show answer and explanation

Answer: A. A part of a program that operates on shared data and must be executed by only one thread at a time

If several threads simultaneously execute code that reads and updates a shared variable, a data race occurs. Such a part, which only one thread should run at a time, is called a critical section and is protected by taking a lock before entering and releasing it on exit. The longer the critical section, the longer other threads wait, so it should be kept as short as possible.

  • A. Correct. It is protected with a lock or similar.
  • B. It is not defined by how long it takes.
  • C. It is not error handling.
Practice this topic Back to topic

More Multicore & Synchronization questions

  1. Which describes barrier synchronization in parallel programs?
  2. When 64 cores continuously update one shared counter with atomic instructions, adding cores does not speed things up. What is the main reason?
  3. Which describes a NUMA (non-uniform memory access) system?
  4. Under the first-touch policy common on Linux NUMA systems (a page is placed in the memory of the node where the thread first writing it runs), what should programmers watch out for?
  5. Which is NOT a reason a parallel program fails to scale as cores are added?