What this C++ concurrency question tests
This is a medium-difficulty question that probes your understanding of the C++ memory model and the formal guarantees the standard provides around thread synchronization and visibility. Rather than asking what a particular compiler happens to do, it challenges you to reason about the defined behaviour specified in the C++ standard itself.
To answer correctly, you need to understand happens-before relationships, memory ordering semantics, and the distinction between data races and well-defined concurrent access. Firms ask this type of question to verify that candidates can reason about correctness in multithreaded code from first principles, not by trial and error against a specific toolchain.
- Happens-before and synchronization-with relations
- Memory ordering (sequentially consistent, acquire-release, relaxed)
- Data races and undefined behaviour
- Mutex and atomic semantics under the standard