Multicore & Synchronization
Which describes a critical section?
- AA part of a program that operates on shared data and must be executed by only one thread at a time
- BThe part of a program that takes the longest time to run
- 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.